|
发表于 2007-9-29 23:38:00
|
显示全部楼层
Re:请教一下关于DLL 使用的问题
/*
myDll.h
*/
#ifndef MYDLL_H
#define MYDLL_H
#ifndef DLLEXPORT
#define DLLEXPORT _declspec(dllexport)
#endif
#include <windows.h>
#include <stdio.h>
class DLLEXPORT MsgBox
{
public:
MsgBox() : m_iData( 0 ) { }
~MsgBox() { }
void showMsg( const char *msg, int data );
protected:
int m_iData;
};
#endif
/*
myDll.cpp
*/
#include "myDll.h"
void MsgBox::showMsg( const char *msg, int data )
{
char info[256] = {0};
sprintf( info, "%s %d", msg, data );
MessageBox( NULL, info, "ok", MB_OK );
}
/*
another project , test.cpp
*/
#include "myDll.h"
#ifdef _DEBUG
#pragma comment( lib, "../lib/dll_d.lib" )
#else
#pragma comment( lib, "../lib/dll.lib" )
#endif
int main()
{
MsgBox msg;
msg.showMsg( "Test my DLL :", 11 );
return 0;
}
__declspec(dllimport) 不是必须的,但是加上后会让效率更高,见MSDN。
|
|