简体   繁体   English

访问dll方法时访问冲突读取位置

[英]Access violation reading location when accessing a dll method

I am using the following code to access a method in the dll file and I am getting an Access violation reading location 0x41100000 when calling the method from the dll method. 我使用以下代码访问dll文件中的方法,并从dll方法调用方法时获取Access violation reading location 0x41100000

The method that I am trying to access is of the following prototype 我尝试访问的方法是以下原型

 int dstoch(float,float,float,float,float,float,float,float,float);

This is my code 这是我的代码

typedef int (*LPMyfunct)(float,float,float,float,float,float,float,float,float);
HINSTANCE hDLL = NULL;
LPMyfunct lpdstoch = NULL;

hDLL = LoadLibrary("c:\\myfile.dll");

if(hDLL!=NULL)
{
    std::cout << "Library loaded \n";
    lpdstoch = (LPMyfunct)GetProcAddress((HMODULE)hDLL, "dstoch");

    int res = 0;
    if(lpdstoch != NULL)
    {
        try
        {
            res = lpdstoch(1.1,2.2,3.3,4.4,5.4,6.4,7.4,8.8,9.9); //Gives the error
        }
        catch (std::exception &e)
        {
            std::cout << e.what();
        }   
    }
}

Any suggestions what the reasons could be ? 有什么建议原因可能是什么? Any chance there is an error in the dll file ? dll文件中是否有错误? Is there any way I could read the parameters of the dll file ? 有什么办法可以读取dll文件的参数吗? Disect it to check if I am getting the parameter types correct ? 请它检查我是否正确获取参数类型? Decpendency checker shows that the method exists but I cant acertain the argument types ? 依赖检查器显示该方法存在,但我不能确定参数类型?

Update: 更新:

I am still getting the error 我仍然得到错误

First-chance exception at 0x0040356c in test.exe: 0xC0000005: Access violation writing location 0x42080000. test.exe中0x0040356c处的第一次机会异常:0xC0000005:访问冲突写入位置0x42080000。 Unhandled exception at 0x0040356c in Cexperiment.exe: 0xC0000005: Access violation writing location 0x42080000. Cexperiment.exe中0x0040356c处的未处理异常:0xC0000005:访问冲突写入位置0x42080000。

I also believe that this issue might not be related to a calling convention .The reason I believe is because I do not get an error message from VS2010 stating that a calling convention may be a cause.I got that message when i tried using some other dll. 我也相信这个问题可能与调用约定无关。我相信的原因是因为我没有收到来自VS2010的错误消息,说明调用约定可能是一个原因。当我尝试使用其他一些时,我收到了该消息DLL。 So if calling convention or parameters are not an issue (you get the same calling convention message incase the parameters are different) then it might be something else. 因此,如果调用约定或参数不是问题(如果参数不同,则会获得相同的调用约定消息),那么它可能是其他内容。 Any suggestions on what I could try ? 关于我可以尝试的任何建议?

You need to check calling convention of the dll function and declare LPMyfunct type accordingly. 您需要检查dll函数的调用约定并相应地声明LPMyfunct类型。 Possible values for calling conventions are: stdcall , cdecl , pascal . 调用约定的可能值为: stdcallcdeclpascal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM