调用dll中包含的函数的问题 [英] problems calling a function contained in a dll

查看:82
本文介绍了调用dll中包含的函数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,


我在Microsoft Visual Studio 2003中加载dll时遇到困难,

由另一家公司提供给我。他们为我提供了

测试代码,导致我的程序崩溃,见下文:


#include" stdafx.h"

#include" stdio.h"

#include" stdlib.h"

#include< windows.h>


typedef bool(__ fastcall * _ANT_Init)(unsigned char ucUSB_,unsigned

short usBaud_);


int _tmain(int argc,_TCHAR * argv [])

{


HINSTANCE hDLLInstance;


_ANT_Init ANT_Init;


printf(尝试加载DLL \ n);

hDLLInstance = LoadLibraryA(" ANT_DLL.dll");


if(hDLLInstance == NULL)

{


fprintf(stderr,错误:无法加载DLL \ n);

返回1;


}


其他

{


printf("成功:加载ANT_DLL.dll \ n");


}

ANT_Init =(_ANT_Init)G etProcAddress(hDLLInstance," _ANT_Init");

if(ANT_Init(0,50000)== true)

{

printf(" ;成功:ANT初始化正确\ n;

}

其他

{

printf(" ;失败:ANT界面未找到\ n;

}


FreeLibrary(hDLLInstance);


printf(ANT DLL Freed\ n);


返回0;


}

每当我的程序崩溃时,我都会收到以下错误消息

" program.exe中0x00000000处的未处理异常:0xC0000005:访问

违规读取位置0x00000000。


用dll提供给我的公司说他们用Borland C ++编译了它,用b
$ b。他们还告诉我要让我的程序正确链接

windows.h文件,我需要安装Windows PSDK

..我已经下载了微软网站的后者,但我仍然得到同样的错误

。从下面的屏幕截图中,您可以看到,SDK

似乎在我的计算机上正确安装。


您有什么建议吗?在此先感谢您的帮助,


问候,


艾伦

Good afternoon,

I''m having difficulties loading a dll in Microsoft Visual Studio 2003,
that was supplied to me by another company. They have supplied me with
test code, which causes my program to crash, see below:

#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include <windows.h>

typedef bool (__fastcall* _ANT_Init)(unsigned char ucUSB_, unsigned
short usBaud_);

int _tmain(int argc, _TCHAR* argv[])
{

HINSTANCE hDLLInstance;

_ANT_Init ANT_Init;

printf("Attempting to load DLL\n");
hDLLInstance = LoadLibraryA("ANT_DLL.dll");

if (hDLLInstance == NULL)
{

fprintf(stderr, "ERROR: Unable to load DLL\n");
return 1;

}

else
{

printf("Success: Loaded ANT_DLL.dll\n");

}
ANT_Init = (_ANT_Init)GetProcAddress(hDLLInstance, "_ANT_Init");
if (ANT_Init(0, 50000) == true)
{
printf("Success: ANT Initialized Properly\n");
}
else
{
printf("Fail: ANT Interface not found\n");
}

FreeLibrary(hDLLInstance);

printf("ANT DLL Freed\n");

return 0;

}
Whenever my program crashes, I get the following error message
"Unhandled exception at 0x00000000 in program.exe: 0xC0000005: Access
violation reading location 0x00000000."

The company that supplied me, with the dll, say that they compiled it,
with Borland C++. They also told me that to get my program to link the
windows.h file in properly, that I need to have Windows PSDK installed
.. I''ve downloaded the latter of the Microsoft web site, but I still get
the same error. From the following screen shot, you can see, that SDK
seems to be installed correctly on my computer.

Do you have any suggestions? Thanks in advance for your help,

Regards,

Alan

推荐答案

Alan写道:
Alan wrote:

下午好,


我在装载时遇到困难Microsoft Visual Studio 2003中的一个DLL,

由另一家公司提供给我。他们为我提供了

测试代码,导致我的程序崩溃,见下文:


#include" stdafx.h"

#include" stdio.h"

#include" stdlib.h"

#include< windows.h>


typedef bool(__ fastcall * _ANT_Init)(unsigned char ucUSB_,unsigned

short usBaud_);


int _tmain(int argc,_TCHAR * argv [])

{


HINSTANCE hDLLInstance;


_ANT_Init ANT_Init;


printf(尝试加载DLL \ n);

hDLLInstance = LoadLibraryA(" ANT_DLL.dll");


if(hDLLInstance == NULL)

{


fprintf(stderr,错误:无法加载DLL \ n);

返回1;


}


其他

{


printf(" Success:Loaded ANT_DLL.dll \ n");


}


ANT_Init =(_ANT_Init)GetProcAddress(hDLLInstance," _ANT_Init");
Good afternoon,

I''m having difficulties loading a dll in Microsoft Visual Studio 2003,
that was supplied to me by another company. They have supplied me with
test code, which causes my program to crash, see below:

#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include <windows.h>

typedef bool (__fastcall* _ANT_Init)(unsigned char ucUSB_, unsigned
short usBaud_);

int _tmain(int argc, _TCHAR* argv[])
{

HINSTANCE hDLLInstance;

_ANT_Init ANT_Init;

printf("Attempting to load DLL\n");
hDLLInstance = LoadLibraryA("ANT_DLL.dll");

if (hDLLInstance == NULL)
{

fprintf(stderr, "ERROR: Unable to load DLL\n");
return 1;

}

else
{

printf("Success: Loaded ANT_DLL.dll\n");

}
ANT_Init = (_ANT_Init)GetProcAddress(hDLLInstance, "_ANT_Init");



if(ANT_Init == NULL)

{

fprintf(stderr," ERROR:Unable to在

DLL \ n")中找到_ANT_Init函数;

返回1;

}

if (ANT_Init == NULL)
{
fprintf(stderr, "ERROR: Unable to find the _ANT_Init function in the
DLL\n");
return 1;
}


if(ANT_Init(0,50000)== true)
if (ANT_Init(0, 50000) == true)



当心。看到这种测试总是吓到我。我建议

如果(ANT_Init(0,50000)!= false)会更安全,尽管我自己会使用

if(ANT_Init(0,50000))。

Beware. Seeing this sort of test always scares me. I would suggest that
if (ANT_Init(0, 50000) != false) would be safer although I would use
if (ANT_Init(0, 50000)) myself.


{

printf(" Success:ANT Initialized Aperly\ n);

}

其他

{

printf(失败:ANT界面未找到\ n);

}


FreeLibrary(hDLLInstance);


printf(ANT DLL Freed\ n);


返回0;


}


每当我的程序崩溃时,我都会收到以下错误消息

program.exe中0x00000000处未处理的异常:0xC0000005:访问

违规读取位置0x00000000。


提供给我的公司, dll,说他们用Borland C ++编译了它,用b
$ b。他们还告诉我,要让我的程序正确链接

windows.h文件,我需要安装Windows PSDK

。我已经下载了微软网站的后者,但我仍然得到了同样的错误

。从下面的屏幕截图中,您可以看到,SDK

似乎在我的计算机上正确安装。


您有什么建议吗?在此先感谢您的帮助,


问候,


Alan
{
printf("Success: ANT Initialized Properly\n");
}
else
{
printf("Fail: ANT Interface not found\n");
}

FreeLibrary(hDLLInstance);

printf("ANT DLL Freed\n");

return 0;

}
Whenever my program crashes, I get the following error message
"Unhandled exception at 0x00000000 in program.exe: 0xC0000005: Access
violation reading location 0x00000000."

The company that supplied me, with the dll, say that they compiled it,
with Borland C++. They also told me that to get my program to link the
windows.h file in properly, that I need to have Windows PSDK installed
. I''ve downloaded the latter of the Microsoft web site, but I still get
the same error. From the following screen shot, you can see, that SDK
seems to be installed correctly on my computer.

Do you have any suggestions? Thanks in advance for your help,

Regards,

Alan



如果这没有显示问题没有找到功能那么我

期望错误在ANT_Init内,我会使用调试器来证明

它并传递问题回到第三方。

-

Bill Medland

If this does not show that the problem is not finding the funtion then I
expect the error is within ANT_Init and I would use the debugger to prove
it and pass the problem back to the third party.
--
Bill Medland


比尔,


感谢您的帖子。我不认为我的问题与ANT_Init返回的值的

测试有关,因为我试图自己调用这个

函数,没有测试返回的值,它确实与

相同。


在调试器中,我能够在此行旁边放置一个断点

代码,但每当我问它时,要步入功能,错误

消息出现。


还有其他任何建议吗?


再次感谢,


Alan

Bill Medland写道:
Hi Bill,

Thank you for your post. I don''t think my problem is related to the
test of the value returned by ANT_Init, as I''ve tried to call this
function by itself, without testing the value returned and it did the
same thing.

Within the debugger, I''m able to place a breakpoint next to this line
of code, but whenever I ask it, to "step into" the function, the error
message appears.

Any other suggestions?

Thanks again,

Alan
Bill Medland wrote:

Alan写道:
Alan wrote:

下午好,


我在Microsoft Visual Studio 2003中加载dll时遇到困难,

提供给我由另一家公司。他们为我提供了

测试代码,导致我的程序崩溃,见下文:


#include" stdafx.h"

#include" stdio.h"

#include" stdlib.h"

#include< windows.h>


typedef bool(__ fastcall * _ANT_Init)(unsigned char ucUSB_,unsigned

short usBaud_);


int _tmain(int argc,_TCHAR * argv [])

{


HINSTANCE hDLLInstance;


_ANT_Init ANT_Init;


printf(尝试加载DLL \ n);

hDLLInstance = LoadLibraryA(" ANT_DLL.dll");


if(hDLLInstance == NULL)

{


fprintf(stderr,错误:无法加载DLL \ n);

返回1;


}


其他

{


printf(&qu ot;成功:加载ANT_DLL.dll \ n");


}

ANT_Init =(_ANT_Init)GetProcAddress(hDLLInstance," _ANT_Init");
Good afternoon,

I''m having difficulties loading a dll in Microsoft Visual Studio 2003,
that was supplied to me by another company. They have supplied me with
test code, which causes my program to crash, see below:

#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include <windows.h>

typedef bool (__fastcall* _ANT_Init)(unsigned char ucUSB_, unsigned
short usBaud_);

int _tmain(int argc, _TCHAR* argv[])
{

HINSTANCE hDLLInstance;

_ANT_Init ANT_Init;

printf("Attempting to load DLL\n");
hDLLInstance = LoadLibraryA("ANT_DLL.dll");

if (hDLLInstance == NULL)
{

fprintf(stderr, "ERROR: Unable to load DLL\n");
return 1;

}

else
{

printf("Success: Loaded ANT_DLL.dll\n");

}
ANT_Init = (_ANT_Init)GetProcAddress(hDLLInstance, "_ANT_Init");



if(ANT_Init == NULL)

{

fprintf(stderr," ERROR:Unable to在

DLL \ n")中找到_ANT_Init函数;

返回1;

}


if (ANT_Init == NULL)
{
fprintf(stderr, "ERROR: Unable to find the _ANT_Init function in the
DLL\n");
return 1;
}


if(ANT_Init(0,50000)== true)
if (ANT_Init(0, 50000) == true)



当心。看到这种测试总是吓到我。我建议

如果(ANT_Init(0,50000)!= false)会更安全,尽管我自己会使用

if(ANT_Init(0,50000))。


Beware. Seeing this sort of test always scares me. I would suggest that
if (ANT_Init(0, 50000) != false) would be safer although I would use
if (ANT_Init(0, 50000)) myself.


{

printf(" Success:ANT Initialized Aperly\ n);

}

其他

{

printf(失败:ANT界面未找到\ n);

}


FreeLibrary(hDLLInstance);


printf(ANT DLL Freed\ n);


返回0;


}

每当我的程序崩溃时,我收到以下错误消息

" Unhandled program.exe中0x00000000处的异常:0xC0000005:访问

违规读取位置0x00000000。


通过dll提供给我的公司说他们用Borland C ++编译了它,
。他们还告诉我,要让我的程序正确链接

windows.h文件,我需要安装Windows PSDK

。我已经下载了微软网站的后者,但我仍然得到了同样的错误

。从下面的屏幕截图中,您可以看到,SDK

似乎在我的计算机上正确安装。


您有什么建议吗?在此先感谢您的帮助,


问候,


Alan
{
printf("Success: ANT Initialized Properly\n");
}
else
{
printf("Fail: ANT Interface not found\n");
}

FreeLibrary(hDLLInstance);

printf("ANT DLL Freed\n");

return 0;

}
Whenever my program crashes, I get the following error message
"Unhandled exception at 0x00000000 in program.exe: 0xC0000005: Access
violation reading location 0x00000000."

The company that supplied me, with the dll, say that they compiled it,
with Borland C++. They also told me that to get my program to link the
windows.h file in properly, that I need to have Windows PSDK installed
. I''ve downloaded the latter of the Microsoft web site, but I still get
the same error. From the following screen shot, you can see, that SDK
seems to be installed correctly on my computer.

Do you have any suggestions? Thanks in advance for your help,

Regards,

Alan



如果这没有显示问题没有找到功能那么我

期望错误在ANT_Init内,我会使用调试器来证明

它并传递问题回到第三方。

-

Bill Medland

If this does not show that the problem is not finding the funtion then I
expect the error is within ANT_Init and I would use the debugger to prove
it and pass the problem back to the third party.
--
Bill Medland


" Alan" < al ********** @ yahoo.co.ukwrites:
"Alan" <al**********@yahoo.co.ukwrites:

我在Microsoft Visual Studio 2003中加载dll时遇到困难,
I''m having difficulties loading a dll in Microsoft Visual Studio 2003,



[snip]


对不起,你在错误的地方。试试与Windows相关的新闻组。

comp.os.ms-windows.programmer.win32 *可能*是正确的地方。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti。 net / ~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

[snip]

Sorry, you''re in the wrong place. Try a Windows-related newsgroup.
comp.os.ms-windows.programmer.win32 *might* be the right place.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于调用dll中包含的函数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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