微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

显式调用一个DLL

谁能告诉我为什么我的SimpleTest应用程序不显示“testing”? DLL加载成功,我只是没有得到任何控制台输出

SimpleDLL.cpp

#include "stdafx.h" #include "SimpleDLL.h" #include "stdafx.h" #include <iostream> int test() { std::cout << "Test" << std::endl; return 0; }

SimpleDLL.h

#ifndef _DLL_TUTORIAL_H_ #define _DLL_TUTORIAL_H_ #include <iostream> #if defined DLL_EXPORT #define DECLDIR __declspec(dllexport) #else #define DECLDIR __declspec(dllimport) #endif DECLDIR int test(); #endif

SimpleTest.cpp

传递额外的wParam / lParam参数?

exe文件的大小vs可用内存

fstream >> int失败?

用非零值填充内存比用零填充内存慢吗?

如何在VC ++中创build线程

#include "stdafx.h" #include <iostream> #include <windows.h> typedef int (*TestFunc)(); int main() { TestFunc _TestFunc; HINSTANCE hInstLibrary = LoadLibrary( _T("SimpleDLL.dll")); if (hInstLibrary) { _TestFunc = (TestFunc)GetProcAddress(hInstLibrary,"Test"); } else { std::cout << "DLL Failed To Load!" << std::endl; } if (_TestFunc) { _TestFunc(); } FreeLibrary(hInstLibrary); return 0; }

如何捕获来自另一个进程的退出消息?

使用Visual Studio 2008编译的C ++ dll可以用于Visual Studio 2005吗?

有没有办法将DB用户密码传入命令行工具MysqLadmin?

如何使用visual studio express进行汇编级debugging?

在Visual Studio中刷新自动完成(IntelliSense)数据库

你需要在__declspec(...)之前声明extern "C" 。 这是因为C ++在导出C ++函数添加名称修饰,并且需要将其声明为C函数才能将Test函数导出为“Test”

正如JoesphH所说的,你需要extern "C"来防止名称被破坏。 除此之外,还没有指定以下编译器开关之一:

Gz __stdcall调用约定:“Test”将被导出为Test@0

Gr __fastcall调用约定:“Test”将被导出为@Test@0

注意:我认为最后一个符号依赖于编译器版本,但仍然不仅仅是“测试”。

此外,根据我的评论检查来自GetProcAddress()返回值,并使用GetLastError()的值来获取失败的原因,如果返回NULL。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐