Delphiにて以下の様なDLLを作成しました。
//Delphi
Type
TESP = function (V: Integer): Integer; stdcall;
Var
cbFunc: TESP;
Function EnumSeq(Addr: Pointer; V: Integer): Boolean; export; stdcall
Var i: Integer;
Begin
Result:=False;
If Addr=nil Then Exit;
@cbFunc:=Addr;
For i:=0 To 10 Do Begin
cbFunc(V*i);
End;
Result:=True;
End;
end.
これをVC++から呼び出して使いたいのですが、なんとか
コンパイルが通るまでにはなり、また関数自体も呼び出
せてはいるのですが、EnumSeqProcが最後まで呼びださ
れたとたんにエラーを起こしてしまいます。
「例外処理 (初回) は DLLTest.exe にあります:
0xC0000005: Access Violation。」
DLL自体を扱うのが初めてで、使い方等色々調べてここま
で来たのですが、なんともこのエラーの原因がわからない
でいます。
わかる方ご教授願えないでしょうか?よろしくお願いいた
します。
//VC++
int EnumSeqProc(int V){
CString str;
str.Format("%d", V);
OutputDebugString(str);
return 0;
}
void CDLLTestDlg::OnTest()
{
HINSTANCE hDLL;
typedef int (*pESP)(int);
bool (_stdcall *EnumSeq)(pESP, int);
hDLL = ::LoadLibrary("CB.DLL");
EnumSeq = (bool(_stdcall*)(pESP, int))::GetProcAddress(hDLL, "EnumSeq");
EnumSeq(EnumSeqProc, 2);
::FreeLibrary(hDLL);
}
> int EnumSeqProc(int V){
int __stdcall EnumSeqProc(int V) {
では?
>int EnumSeqProc(int V){
int __stdcall EnumSeqProc(int V) {
>typedef int (*pESP)(int);
typedef int (_stdcall *pESP)(int);
とすることで解決することができました。
まだ、_stdcallとかよく理解してないですが、これから調べてみようと
思います。
本当にありがとうございました。
ツイート | ![]() |