C语言如何导入一个dll(动态链接库)

新建一个控制台程序,将动态链接库文件Test63,dll拷贝到源文件统计目录下,在主程序中添加如下代码

// import.cpp : Defines the entry point for the console application.
//

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

typedef int (*MyMessageBox)(char* lpText,char* lpCaption);

int main(int argc, char* argv[])
{
    
    
	HMODULE hModule=LoadLibrary("Test63.dll");

	MyMessageBox NewMessageBox=(MyMessageBox)GetProcAddress(hModule,"MyMessageBox");

	NewMessageBox("by chen","Hello World!");

	FreeLibrary(hModule);

	return 0;
}

编译执行可以看到如下效果
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/chendongpu/article/details/121351602
今日推荐