没有lib 怎么调用DLL 的函数

swlilike 2010-05-09 08:16:40
有DLL,知道里面的函数名跟参数,但是没有lib

想调用那个函数,麻烦详细说下步骤
...全文
386 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
renxu350 2010-05-09
  • 打赏
  • 举报
回复
注意wchar_t的定义要加L
renxu350 2010-05-09
  • 打赏
  • 举报
回复
试试看这个,WIN32版本的,在你的要调用的CPP文件开头定义一个常量段:

#pragma const_seg( "CONST_SEGMENT" )
wchar_t *wchDllFile = L"需要调用的DLL文件名.DLL";
char *chProcName = "需要调用的函数名";
#pragma const_seg()

然后调用函数:

HINSTANCE hDllInstance = ::LoadLibrary( wchDllFile );
FARPROC hProc = ::GetProcAddress( hDllInstance, chProcName );

然后就可以使用你的函数了,比如:

hProc( Param1, Param2 );
swlilike 2010-05-09
  • 打赏
  • 举报
回复
---------------------------
Error
---------------------------
Not found the kernel library or the kernel library is invalid or the kernel library of this edition does not support DLL!
---------------------------
确定
---------------------------


现在函数找到了 但是调用函数的时候 提示这个 为什么呢
lmxmx 2010-05-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 swlilike 的回复:]
C/C++ code
HINSTANCE h;
int *fun;
h = LoadLibrary("ycode.dll");
if(h!=NULL)
{
fun =(int *)GetProcAddress(h,"loadcode");
}


找到这么一个代码 头一行 h 就为空
[/Quote]


你的代码没错,
如果LoadLibrary()失败,
就使用GetLastError()看看错误是什么 ……

Cooliess 2010-05-09
  • 打赏
  • 举报
回复
void CTestDlg::OnBtnDynamic()    
{
// TODO: Add your control notification handler code here
// 动态加载的方法:
// 不需要引入头文件与lib文件,仅需要一个dll即可
// 注意这里的条约调用约定_stdcall不要忘记加(不然会引会esp出错)

typedef int (_stdcall *ADDPROC)(int,int);
typedef int (_stdcall *SUBPROC)(int,int);
HINSTANCE handle;
handle = LoadLibrary("MyDll.dll");
if(handle)
{
// GetProcAddress第二个参数有两种方法:
// 1、通过DLL中的函数名
// 2、通过Depend工具中Ordinal索引值来查看
ADDPROC MyAdd = (ADDPROC)GetProcAddress(handle,"Add");
SUBPROC MySub = (ADDPROC)GetProcAddress(handle,MAKEINTRESOURCE(2));
if( !MyAdd )
{
MessageBox("函数Add地址获取失败!");
return;
}
if( !MySub )
{
MessageBox("函数Sub地址获取失败!");
return;
}
CString str;
str.Format("动态加载: 1+1=%d 1-1=%d",MyAdd(1,1),MySub(1,1));
MessageBox(str);
}
FreeLibrary(handle);
}
swlilike 2010-05-09
  • 打赏
  • 举报
回复
        HINSTANCE h;
int *fun;
h = LoadLibrary("ycode.dll");
if(h!=NULL)
{
fun =(int *)GetProcAddress(h,"loadcode");
}


找到这么一个代码 头一行 h 就为空
Cooliess 2010-05-09
  • 打赏
  • 举报
回复
貌似有工具可以搞吧!

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧