Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am porting my project to x64.
As a x86 project, BCRMaster is a dll with exported functions defined in a .DEF file
They work like a champ.

Now that everything is compiled to x64, I am having trouble with 'corrupted" data being received at BCRMaster's functions. I am calling them from an x64 app.

GetProcAddress succeeds.
LoadLibrary also succeeds.

The actual call of the function succeed in as much as the dll function is indeed called but while I am sending two ints 0 and 1 (simplified for testing), what arrives at the dll function is 1 and 11.

The code is the same in the x86 version where it works as expected.

I have found that other functions are working correctly while this one and at least another are not. Both are "sending" bogus data.

What could be wrong?

Thanks in advance,

:Ron



typedef void (CALLBACK* LPFNDLLFUNC1)(int Unit,int Preset);

   HINSTANCE hDLL;               // Handle to DLL
   LPFNDLLFUNC1 lpfnDllFunc1;    // Function pointer
   DWORD dwParam1 = NULL;

   UINT uReturnVal;
   hDLL = LoadLibrary("BCRMaster");
   if (hDLL != NULL)
   {
    lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL, "SetBcrPreset");

      if (!lpfnDllFunc1)
      {

         // handle the error
        FreeLibrary(hDLL);
          return;

      }else{
       lpfnDllFunc1(0,1); // call the dll function
      }
   }
Posted
Comments
Andrew Brock 13-Nov-11 0:26am    
Are you using the Visual Studio compiler, or another one?
Also, can you provide at least the prototype of the function SetBcrPreset from the DLL code. The prototype should be
extern "C" void CALLBACK SetBcrPreset(int Unit, int Preset);
Ron Anders 13-Nov-11 17:24pm    
Hi,

Thanks for your reply.
I am using vc2008 and no my prototype in only

void SetBcrPreset(int Unit,int Preset);

But I'll change it to extern "C" ... and report back.

It is now:
extern "C" void SetBcrPreset(int Unit,int Preset);


which causes a string of compile errors like so.

1>Compiling...
1>BCRMaster.cpp
1>c:\bcrmaster\control_source\BCRMaster.h(292) : error C2059: syntax error : 'string'
1>c:\bcrmaster\control_source\BCRMaster.h(292) : error C2238: unexpected token(s) preceding ';'

etc...

I thought it might be fixed but I was mistaken
 
Share this answer
 
v2
If you have not fixed it, do this.

C++ encodes the return and argument types into the function name, so when you export it to the DLL, it has a strange name. You need C export to avoid this name mangling.

You also need the same calling convention. This is what the CALLBACK does, and you must export with this too (or get rid of it from your definition of LPFNDLLFUNC1.

Make it like this:
C++
extern "C" void CALLBACK SetBcrPreset(int Unit, int Preset) {
	//This function has the correct name exported to the DLL
	InternalSetBcrPreset(Unit, Preset);
}

void InternalSetBcrPreset(int Unit, int Preset) {
	//Your original code from SetBcrPreset
	//This function exists in C++, so you can do all your C++ stuff in here, such as the string class you had issues with
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900