本人是VC初学者,但老总非叫用一下动态库以前从来没用VC,在网上找了个例子。
建了个名子为Sample的动态库,创 建Sample.def 文 件 Sample.def 文 件 里面:
LIBRARY Sample
EXPORTS
ShowMe Sample.def.cpp里面:写#include "stdafx.h"BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}//Sample.cpp
//Sample.cpp
#include "StdAfx.h"
#include <iostream.h>
#include "stdio.h"
#include "Math.h"
#include "winsock.h"
#include <windows.h>
int ShowMe(void);
//DllEntryPoint为DLL入口点函数,
//负责初试化并终止DLL
BOOL WINAPI DllEntryPoint(HINSTANCE
hDLL,DWORD dwReason,LPVOID Reserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
{
break;
}
case DLL_PROCESS_DETACH:
{
break;
}
}
return TRUE;
}
int ShowMe(void)
{
//蜂鸣器响一下
MessageBeep((WORD)-1);
MessageBox("你好");
cout<<"fadsfa"<<endl;
}
老是说有
C:\Sample\Sample.cpp(52) : error C2660: 'MessageBoxA' : function does not take 1 parameters
这样的错误。
注销掉MessageBox("你好");编译就没错。请问我错在哪里?MessageBox()
用的参数有问题吗?我又没MSDN没法查。还是其他方面错了。网上的例子是这样的啊。怎么解决呢?谢谢大家了。
建了个名子为Sample的动态库,创 建Sample.def 文 件 Sample.def 文 件 里面:
LIBRARY Sample
EXPORTS
ShowMe Sample.def.cpp里面:写#include "stdafx.h"BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}//Sample.cpp
//Sample.cpp
#include "StdAfx.h"
#include <iostream.h>
#include "stdio.h"
#include "Math.h"
#include "winsock.h"
#include <windows.h>
int ShowMe(void);
//DllEntryPoint为DLL入口点函数,
//负责初试化并终止DLL
BOOL WINAPI DllEntryPoint(HINSTANCE
hDLL,DWORD dwReason,LPVOID Reserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
{
break;
}
case DLL_PROCESS_DETACH:
{
break;
}
}
return TRUE;
}
int ShowMe(void)
{
//蜂鸣器响一下
MessageBeep((WORD)-1);
MessageBox("你好");
cout<<"fadsfa"<<endl;
}
老是说有
C:\Sample\Sample.cpp(52) : error C2660: 'MessageBoxA' : function does not take 1 parameters
这样的错误。
注销掉MessageBox("你好");编译就没错。请问我错在哪里?MessageBox()
用的参数有问题吗?我又没MSDN没法查。还是其他方面错了。网上的例子是这样的啊。怎么解决呢?谢谢大家了。
int MessageBox( HWND hWnd, // handle of owner window
LPCTSTR lpText, // address of text in message box
LPCTSTR lpCaption, // address of title of message box
UINT uType // style of message box
);
ParametershWndIdentifies the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window. lpTextPoints to a null-terminated string containing the message to be displayed. lpCaptionPoints to a null-terminated string used for the dialog box title. If this parameter is NULL, the default title Error is used. uTypeSpecifies a set of bit flags that determine the contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags.
Specify one of the following flags to indicate the buttons contained in the message box:Flag Meaning
MB_ABORTRETRYIGNORE The message box contains three push buttons: Abort, Retry, and Ignore.
MB_OK The message box contains one push button: OK. This is the default.
MB_OKCANCEL The message box contains two push buttons: OK and Cancel.
MB_RETRYCANCEL The message box contains two push buttons: Retry and Cancel.
MB_YESNO The message box contains two push buttons: Yes and No.
MB_YESNOCANCEL The message box contains three push buttons: Yes, No, and Cancel.
Specify one of the following flags to display an icon in the message box:Flag Meaning
MB_ICONEXCLAMATION,
MB_ICONWARNING
An exclamation-point icon appears in the message box.
MB_ICONINFORMATION, MB_ICONASTERISK
An icon consisting of a lowercase letter i in a circle appears in the message box.
MB_ICONQUESTION A question- icon appears in the message box.
MB_ICONSTOP,
MB_ICONERROR,
MB_ICONHAND
A stop-sign icon appears in the message box.
9X没实验过。请指教。
AfxMessageBox("sdfds")//这个就可以
AfxMessageBox(" message ")
后
C:\Sample\Sample.cpp(53) : error C2065: 'AfxMessageBox' : undeclared identifier
又抱这个错误请问我少什么定义的头文件吗还是少什么东西吗应该在哪里添!谢谢。
加在#include <windows.h>的前面
project->settings->general->microsoft foundation classes 里的选项只要不是not using MFC
int MessageBox( LPCTSTR lpszText, LPCTSTR lpszCaption = NULL, UINT nType = MB_OK );2、windows API函数 ::MessageBox
int MessageBox(
HWND hWnd, // handle to owner window
LPCTSTR lpText, // text in message box
LPCTSTR lpCaption, // message box title
UINT uType // message box style
);
3、AfxMessageBox
int AfxMessageBox( LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0 );int AFXAPI AfxMessageBox( UINT nIDPrompt, UINT nType = MB_OK, UINT nIDHelp = (UINT) -1 );
可是编译的时候没错。但又报出这样的错误
fcs42d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in Sample.obj
mfcs42d.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in Sample.obj; second definition ignored
Creating library Debug/Sample.lib and object Debug/Sample.exp
Debug/Sample.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.Sample.dll - 2 error(s), 1 warning(s)