x86到x64的移植问题(调用导出的DLL函数)64到64 [英] x86 to x64 porting problem (calling exported DLL functions) 64 to 64

查看:104
本文介绍了x86到x64的移植问题(调用导出的DLL函数)64到64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在将我的项目移植到x64.
作为一个x86项目,BCRMaster是一个dll,具有在.DEF文件中定义的导出函数.
他们像冠军一样工作.

现在,所有内容都已编译为x64,我无法在BCRMaster的函数中接收到损坏的"数据.我正在从x64应用程序中调用它们.

GetProcAddress成功.
LoadLibrary也成功.

函数的实际调用与dll函数的调用一样成功,但是当我发送两个整数0和1(简化测试)时,到达dll函数的是1和11.

该代码在x86版本中与预期的工作方式相同.

我发现其他功能正常运行,而这一功能和至少另一功能则无法正常工作.两者都是发送"伪造数据.

有什么问题吗?

预先感谢,

:罗恩



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
      }
   }

推荐答案

我认为它可能已修复,但我弄错了
I thought it might be fixed but I was mistaken


如果您尚未修复,请执行此操作.

C ++将返回和参数类型编码为函数名称,因此,将其导出到DLL时,它具有一个奇怪的名称.您需要C导出以避免此名称混乱.

您还需要相同的调用约定.这就是CALLBACK的功能,您也必须与此一起导出(或从LPFNDLLFUNC1的定义中删除它.

像这样:
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:
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
}


这篇关于x86到x64的移植问题(调用导出的DLL函数)64到64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆