---math.h文件
#include <string>
extern "C" __declspec(dllexport) int pascal Test(int i,int j);
//extern "C" class CMath
//{
//public:
// CMath(void);
// __declspec(dllexport) int pascal Add(int i,int j);
// ~CMath(void);
//};
---math.cpp文件
#include "StdAfx.h"
#include "Math.h"
int pascal Test(int i,int j)
{
return i+j;
}VS2010,编译生成了firt.dll文件-----------------------client----------------------
-------------test.cpp--------------
#include<iostream>
#include<windows.h>
typedef int ( _stdcall *FUN)(int,int);
int main(void)
{
HINSTANCE hinst=::LoadLibraryA("first.dll");
if(NULL != hinst)
{
std::cout<<"DLL is Load"<<std::endl;
FUN f=(FUN)GetProcAddress(hinst,"1");
if(f==NULL)
{
std::cout<<"Error"<<std::endl;
}
else
{
int k=f(2,3);
std::cout<<k<<std::endl;
}
}
else
{
std::cout<<"Dll isn't Load"<<std::endl;
}
std::cin.get();
}
loadlibrary能成功,但是GetProcAddress总是返回NULL。请问为什么?
#include <string>
extern "C" __declspec(dllexport) int pascal Test(int i,int j);
//extern "C" class CMath
//{
//public:
// CMath(void);
// __declspec(dllexport) int pascal Add(int i,int j);
// ~CMath(void);
//};
---math.cpp文件
#include "StdAfx.h"
#include "Math.h"
int pascal Test(int i,int j)
{
return i+j;
}VS2010,编译生成了firt.dll文件-----------------------client----------------------
-------------test.cpp--------------
#include<iostream>
#include<windows.h>
typedef int ( _stdcall *FUN)(int,int);
int main(void)
{
HINSTANCE hinst=::LoadLibraryA("first.dll");
if(NULL != hinst)
{
std::cout<<"DLL is Load"<<std::endl;
FUN f=(FUN)GetProcAddress(hinst,"1");
if(f==NULL)
{
std::cout<<"Error"<<std::endl;
}
else
{
int k=f(2,3);
std::cout<<k<<std::endl;
}
}
else
{
std::cout<<"Dll isn't Load"<<std::endl;
}
std::cin.get();
}
loadlibrary能成功,但是GetProcAddress总是返回NULL。请问为什么?
解决方案 »
- 子窗口置顶(具有WS_EX_TOPMOST属性),当点击其他进程时依然置顶!
- 外网通信socket问题?
- 求助-多线程的MFC对话框程序溢出了
- MFC扩展DLL可以导出不是派生自MFC的类吗?下面为什么出错?
- 想用两个工程做一个dll,一个工程当然就是dll,另一个工程是静态库lib,现在想让此dll的输出函数由这个静态库工程实现,怎么做???
- 为方便网友,300分求问com组件的支持参数与mfc的支持的参数相互转换的方法?!
- vc60中的一个问题,
- ***怎样在CString里面加入"双引号"???
- 怎样用VC改变CListCtrl(风格是报表)的Itemr的宽并......
- 如何使用VS2017 C++开发游戏?跪求路过的大佬们救救迷途的孩子。。。
- 紧急求助关于OCX单例的实现
- MFC中窗口的弹出,小弟新手
FUN f=(FUN)GetProcAddress(hinst,"Test"); 也返回NULL。我在网上看到别人说用导出函数的序号,所以我把Test换成了1 还是不行。
初学
用def文件或者link的/export参数
改了之后还是_Test@8,若是用DEF文件来定义导出函数,则为Test。觉得以后还是用DEF文件来处理导出函数名称。问题虽然解决了,但是我还是不知道为什么我加了extern "C"修饰符之后,编译器编译出来的导出函数还是_Test@8 求大牛解释。
你不加extern "C"更乱