I currently wrote a Delphi DLL. I can use it perfectly in VB.NET but when I try to use it in VC++ i get problems.
the problem is: i can call the exported function once and get the current value back, however if I call the function again, it returns the last value for that function.
//Delphi 7 Code:
function GetBufferIndex1(): byte; export; stdcall;
begin
Result := ReadBuffer[1];
end;
exports GetBufferIndex1;
//VC++ Code:
#include #include int main(int argc, char* argv[])
{
HINSTANCE LoadMe;
LoadMe = LoadLibrary("xbcdrc.dll");
typedef unsigned char (__stdcall *CreateFn)();
CreateFn LibMEP;
unsigned char x;
LibMEP = (CreateFn)GetProcAddress(LoadMe, "GetBufferIndex1");
x = LibMEP();
LibMEP = (CreateFn)GetProcAddress(LoadMe, "GetBufferIndex1");
x = LibMEP();
FreeLibrary(LoadMe);
return 0;
}
When I restart the application it will return a new value. I am sure that the DLL is correct to most extent because VB.NET has no problems with it. I am not sure if there is a problem with the Delphi DLL code or with the way I am calling the DLL in VC++
Any and all help is appreciated.
Comments
:
: the problem is: i can call the exported function once and get the current value back, however if I call the function again, it returns the last value for that function.
:
: //Delphi 7 Code:
: function GetBufferIndex1(): byte; export; stdcall;
: begin
: Result := ReadBuffer[1];
: end;
:
: exports GetBufferIndex1;
:
:
: //VC++ Code:
: #include
: #include
: int main(int argc, char* argv[])
: {
: HINSTANCE LoadMe;
: LoadMe = LoadLibrary("xbcdrc.dll");
:
: typedef unsigned char (__stdcall *CreateFn)();
: CreateFn LibMEP;
:
: unsigned char x;
:
: LibMEP = (CreateFn)GetProcAddress(LoadMe, "GetBufferIndex1");
: x = LibMEP();
: LibMEP = (CreateFn)GetProcAddress(LoadMe, "GetBufferIndex1");
: x = LibMEP();
:
: FreeLibrary(LoadMe);
: return 0;
: }
:
: When I restart the application it will return a new value. I am sure that the DLL is correct to most extent because VB.NET has no problems with it. I am not sure if there is a problem with the Delphi DLL code or with the way I am calling the DLL in VC++
:
: Any and all help is appreciated.
:
You only need to call GetProcAddress() once. It will simply return the pointer to the procedure. Perhaps the name-mangling of C causes a difference in procedure pointers. Or C might reset any open file handles upon calling GetProcAddress(). These are the only things I can come up with, which might cause the problem.