您的位置:首页 > 编程语言

VC常用代码之动态加载DLL

2008-10-21 16:12 357 查看
根据MSDN:

// File: RUNTIME.C

// A simple program that uses LoadLibrary and

// GetProcAddress to access myPuts from MYPUTS.DLL.

#include <stdio.h>

#include <windows.h>

typedef VOID (*MYPROC)(LPTSTR);

VOID main(VOID)

{

HINSTANCE hinstLib;

MYPROC ProcAdd;

BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;

// Get a handle to the DLL module.

hinstLib = LoadLibrary("myputs");

// If the handle is valid, try to get the function address.

if (hinstLib != NULL)

{

ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts");

// If the function address is valid, call the function.

if (fRunTimeLinkSuccess = (ProcAdd != NULL))

(ProcAdd) ("message via DLL function/n");

// Free the DLL module.

fFreeResult = FreeLibrary(hinstLib);

}

// If unable to call the DLL function, use an alternative.

if (! fRunTimeLinkSuccess)

printf("message via alternative method/n");

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: