![]() |
General Programming »
DLLs & Assemblies »
Beginners
Beginner
Creation of a Simple DLLBy VGirishSteps to create your first DLL file |
VC6, VC7Win2K, WinXP, Visual-Studio, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
This article shows a step-by-step technique to create your first DLL with VC++.
CWinApp file.
# include <stdafx.h>
# include "SourceFile.h"
class CDllApp : public CWinApp
{
public:
CDllApp::CDllApp()
{
Calc(0,0);
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CDllApp,CWinApp)
END_MESSAGE_MAP()
CDllApp DllObject;
dllexport value for the _declspec function.
extern "C" _declspec(dllexport) int Calc(char no1,char no2)
{
char result;
result = no1 + no2;
return result;
}
dllimport value of _declspec.
extern "C" _declspec(dllimport) Calc(int FirstValue,
int SecondValue);
# include "AFXWIN.H"
# include "AppHeader.h"
class MainFrame : public CFrameWnd
{
public:
MainFrame()
{
Create(0,"Trial");
}
void OnLButtonDown(UINT nFlags,CPoint point)
{
int res;
char str[5];
res = Calc(998,226);
sprintf(str,"%d",res);
MessageBox(str);
}
DECLARE_MESSAGE_MAP()
};
The DLL file may not be visible due to the File View options in the Windows folder. So, you can either go to the DOS prompt and copy the file or enable the setting "Show all files" in Windows Explorer to copy the file. To create a DLL that uses MFC, see the following example. Note that extern "C" has not been used and the macro AFX_MANAGE_STATE(AfxGetStaticModuleState()); has been used to implement MFC.
_declspec(dllexport)CString Display(CString a,CString b)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CString Str;
Str = a + b;
return Str;
}
That's all, folks. All luck and have a great time.
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 28 Jun 2002 Editor: Genevieve Sovereign |
Copyright 2002 by VGirish Everything else Copyright © CodeProject, 1999-2010 Web19 | Advertise on the Code Project |