이 게시판은 아별닷컴 회원만 질문을 올릴 수 있습니다. 회원에게 주어지는 특권인셈이지요. 회원이 아닌 분들은 열람만 가능합니다.
글 수 113
안녕하세요? 아별님이틀내내 인터넷에 찾아보고 해도 문제를 풀지 못해 부탁 드립니다. Excel에서 DLL을 실행시키기 위해 아래와 같은 아주 간단한 VC 2008로 MyDllAny.dll을 만들고 그 결과를 메세지창에 띄우려고 합니다.그런데 계속 에러가 나서 염치 불구하고 어디가 잘못 되었는지 부탁드립니다.이 사이트에 예제파일은 잘 작동이 되던데 제가 만든것은 DLL호출규정이 잘못되었다는 메세지가 나옵니다. VB로 실행파일을 만들어 테스트하면 잘 되는데 Excel 파일에서 Load하면 안되는군요.번거러우시겠지만 어디가 문제가 되는지 알려주시면 감사하겠습니다. OS : Windows 7 64 BitExcel : Excel 2007 32 BitC Compiler : Visual C 2008 // DLL 파일 컴파일 VB : Visual Studio 2008 // 단지 Test용으로 실행파일 만든 용도며 실제 관련없음. // C DLL 프로그램 내용 /* 직접 익스포트하기 */
extern "C" __declspec(dllexport) int AddInteger(int a, int b)
{
return a+b;
}
//*///* 헤더 파일로 익스포트하기
#define DLLEXPORT
#include "MyDll.h"extern "C" MYDLLTYPE int AddInteger(int a, int b)
{
return a+b;
}
//*/ ***** REM Excel module
#If Win64 Then
Private Declare PtrSafe Function AddInteger Lib "D:\Test\MyDll64.dll" (ByVal a As integer, ByVal b As Integer) As IntPtr
#Else
Public Declare Function AddInteger Lib "D:\Test\MyDllAny.dll" (ByVal A As Integer, ByVal B As Integer) As Integer
#End IfSub ButtonClick()
Dim A As Integer
Dim B As Integer
Dim Result As Integer
Result = 100
Result = AddInteger(A, B)
MsgBox Str(Result)
End Sub Visual Basic 부분**** REM Visual Basic에서는 실행이 잘됩니다. 첨부파일 중 실행파일로 만든것Public Class Form1
REM Attribute VB_Name = "Module1"
Declare Function AddInteger Lib "MyDllAny.dll" (ByVal A As Integer, ByVal B As Integer) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Result As Integer
Result = AddInteger(3, 4)
Me.Label1.Text = "3+4=" + Str(Result)
End Sub
End Class
extern "C" __declspec(dllexport) int AddInteger(int a, int b)
{
return a+b;
}
//*///* 헤더 파일로 익스포트하기
#define DLLEXPORT
#include "MyDll.h"extern "C" MYDLLTYPE int AddInteger(int a, int b)
{
return a+b;
}
//*/ ***** REM Excel module
#If Win64 Then
Private Declare PtrSafe Function AddInteger Lib "D:\Test\MyDll64.dll" (ByVal a As integer, ByVal b As Integer) As IntPtr
#Else
Public Declare Function AddInteger Lib "D:\Test\MyDllAny.dll" (ByVal A As Integer, ByVal B As Integer) As Integer
#End IfSub ButtonClick()
Dim A As Integer
Dim B As Integer
Dim Result As Integer
Result = 100
Result = AddInteger(A, B)
MsgBox Str(Result)
End Sub Visual Basic 부분**** REM Visual Basic에서는 실행이 잘됩니다. 첨부파일 중 실행파일로 만든것Public Class Form1
REM Attribute VB_Name = "Module1"
Declare Function AddInteger Lib "MyDllAny.dll" (ByVal A As Integer, ByVal B As Integer) As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Result As Integer
Result = AddInteger(3, 4)
Me.Label1.Text = "3+4=" + Str(Result)
End Sub
End Class
Private Declare PtrSafe Function AddInteger Lib "D:/Test/MyDll32.dll" (ByVal a As Long, ByVal b As Long) As Long
#Else
Private Declare Function AddInteger Lib "D:/Test/MyDll32.dll" (ByVal a As Long, ByVal b As Long) As Long
#End If 2. Windows 7 64Bit Office 2007 32 Bit 1) C에서 DLL 파일을 만들때 def 파일을 이용해서 만들것 Ex) MyDll32.defLIBRARY "MyDll32"EXPORTSAddInteger @1 VC, VB로 만든 실행파일과 Excel2010으로서 동일한 dll 파일을 loading하는것은 전혀 문제가 없었으나 Excel 2007에서는 문제가 발생,따라서 dll 파일을 만들때 함수 export부분을 구 방식으로 만들어야 합니다.