分类:
2008-09-17 11:10:58
()
- ()
-- ()
[求助] dll编程
用VC编的程序,调用VC编的DLL,都在VC++6.0上开发。
动态链接库的函数为:
Handle(Geom_Surface) mysurfacedll;
_declspec(dllexport) int myfunc(Handle(Geom_Surface)* mys)
{
mysurfacedll = *mys;
return 1;
}
运行程序中添加了该库,调用如下:
void CSTViewerDoc::OnExtractMeancurvature() //提取面的平均曲率的菜单按钮
{
// TODO: Add your command handler code here
HINSTANCE hDll;
hDll = LoadLibrary("mfcsample.dll");
typedef int(_cdecl *Connect)(Handle(Geom_Surface)*);
if (NULL==hDll)
{
AfxMessageBox("动态链接库加载失败");
return ;
}
Connect Proc;
Proc = (Connect)GetProcAddress (hDll,"myfunc");//Testfunc所调用的函数
if (NULL==Proc){
AfxMessageBox("动态链接库中函数寻找失败");
return;
}
//int iValue = Proc(&mySurface);
FreeLibrary(hDll);
.......//执行后续提取信息的功能的代码。
}
问题是:当直接点击该菜单按钮,可以获得hDll,说明DLL加载成功了。但是,现在,我须要先执行一部分其他操作后,才想加载DLL,于是我把代码改为:
void CSTViewerDoc::OnExtractMeancurvature() //提取面的平均曲率的菜单按钮
{
// TODO: Add your command handler code here
...........................//部分前序功能代码,比如选择将要提取曲率的面
HINSTANCE hDll;
hDll = LoadLibrary("mfcsample.dll");
typedef int(_cdecl *Connect)(Handle(Geom_Surface)*);
if (NULL==hDll)
{
AfxMessageBox("动态链接库加载失败");
return ;
}
Connect Proc;
Proc = (Connect)GetProcAddress (hDll,"myfunc");//Testfunc所调用的函数
if (NULL==Proc){
AfxMessageBox("动态链接库中函数寻找失败");
return;
}
//int iValue = Proc(&mySurface);
FreeLibrary(hDll);
.......//执行后续提取信息的功能的代码。
}
但是,因为添加了一些前序代码,此时,hDll = LoadLibrary("mfcsample.dll"); 怎么都加载不成功,运行总是弹出“动态链接库加载失败”的消息。说明(NULL==hDll) 。后来我也试过了先加载DLL,然后,执行前序代码,接着再调用函数,不过结果也是弹出“动态链接库加载失败”的消息。请问这个是什么原因,该怎么解决。谢谢!
考虑了好久,总是行不通,有没有好的办法,可行性如何,请高手指教!
1,加载程序是否能够收搜到DLL?
2,把DLL中的DllMain函数中,直接返回TRUE,然后加载,如果这步能过去,再把你的代码加进来.
__________________
if(有电&&有电脑)
{
Programing();
}
else
{
Sleeping();
}
全部时间均为北京时间. 现在时间是14:05 . |
Powered by: vBulletin Version 2.2.8
Translated and hacked by:
Copyright © Jelsoft Enterprises Limited 2000, 2001.