64位问题_alloca问题 [英] 64 bit issue _alloca problem

查看:131
本文介绍了64位问题_alloca问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VC ++ 2010中的X64代码中遇到问题.我的32位代码工作正常,但在64位中,我具有动态分配的功能,如下所示.我有一个具有两个参数的函数,我可以使用加载库加载dll运行时.当我获取价值时,我的第二个论点 被第一个替换,第二个参数包含垃圾值.我的要求是我必须在运行时使用动态参数列表加载dll函数.以下是我的代码

I have problem in X64 code in VC++ 2010. My code in 32 bit works fine but in 64 i have function with dynamical allocation as under. I have a function having two parameter i to load dll runtime using load library. When i retrieve value my second argument is replaced by first and my second argument contain garbage value. My requirement is that i have to load dll functions on runtime with dynamic list of parameters.  Below is my code 

FARPROC pProcAddr;

FARPROC pProcAddr;

pProcAddr = GetProcAddress(hInstance,"function1"))))

pProcAddr = GetProcAddress( hInstance,"function1" ) ) )

p缓冲所有参数.

nBufferSize是缓冲区大小

nBufferSize is buffer size

LPVOID pStack = _alloca(nBufferSize); //在堆栈上分配参数块

LPVOID pStack = _alloca( nBufferSize ); // Allocate parameter block on a stack

memcpy(pStack,pBuffer,nBufferSize); //将参数块复制到堆栈中

 memcpy( pStack, pBuffer, nBufferSize ); // Copy parameter block to stack

//功能调用

pReturn =(* pProcAddr)();       

pReturn = (*pProcAddr)();       

 

此致

法赫德·安瓦尔     

Fahd Anwar      

 

推荐答案

问题不在于alloca,而在于x86和x64之间的调用约定.您应该阅读以下内容:

The problem is not alloca but the difference in calling convention between x86 and x64. You should read the following:

http://msdn.microsoft.com /en-US/library/ms235286(v=VS.100).aspx

但是我不确定您想做的事是否确实可行. x64调用约定使用寄存器来传递某些参数,并且x64编译器不允许内联汇编程序.我看不到如何模拟函数调用 这种情况.

but I'm not sure if what you want to do is actually possible. The x64 calling convention uses registers to pass some of the arguments and at the same the x64 compiler doesn't allow inline assembler. I don't see how you could simulate a function call in this circumstances.


这篇关于64位问题_alloca问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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