Click here to Skip to main content
15,909,199 members
Articles / Programming Languages / C++
Article

How use from a Dll in our programs.

Rate me:
Please Sign up or sign in to vote.
1.06/5 (13 votes)
16 Sep 2005CPOL 26.2K   318   10   4
Use from a Dll file .this is a good example for this task.

Sample Image - UseInfoWindows_behzadbahjatmanesh.gif

Introduction

How use from a Dll in our programs.

this is  a good example for this task.

this Dll is programed by me.(Name of Dll is InfoWindows.dll )

in this Dll , I use from Four Fuctions.

that are : 

<P dir=ltr>1. BOOL IsWindowsNT(void)</P><P dir=ltr>2. CString GetPathWindows(void)</P><P dir=ltr>3. CString GetPathSystem(void)</P><P dir=ltr>4. CString GetDriveCDrom(void)</P>

1. Bool IsWindowsNT (void)

we can use this fuction to distinguish winNT from Win98.

2. CString GetPathWindows(void)

we can use this fuction to distinguish path of our installed windows.

3. CString GetPathSystem(void)

we can use this fuction to distinguish path of  system  folder.

4. CString GetDriveCDrom(void)

we can use this fuction to distinguish path of our CDrom.

Notice:

To useing Dll File we must be Copy Dll file into System Folder of our Windows.

See part of program together :

// UseInfoWindowsDllDlg.cpp : implementation file
// 
/////////////////////////////////////////////////
//
// Programmer : Behzad Bahjat Manesh .
// Date : 2005/06/06
// Email :Bahjatmanesh@gmail.com
//
// 
/////////////////////////////////////////////////<P></P>
<P dir=ltr>#include "stdafx.h"
#include "UseInfoWindowsDll.h"
#include "UseInfoWindowsDllDlg.h"</P>
<P dir=ltr> </P>
<P dir=ltr>#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static 
char THIS_FILE[] = __FILE__;
#endif</P>
<P dir=ltr>//----------Fuctions Dllfile----------</P>
<P dir=ltr>
HINSTANCE gLibMyDLL =NULL;</P>
<P dir=ltr>typedef CString (*GETPATHWINDOWS) (void);
GETPATHWINDOWS 
GetPathWindows;</P>
<P dir=ltr>
typedef CString (*GETPATHSYSTEM) (void);
GETPATHSYSTEM 
GetPathSystem;</P>
<P dir=ltr> </P>
<P dir=ltr>typedef  BOOL (*ISWINDOWSNT) (void);
ISWINDOWSNT 
IsWindowsNT;</P>
<P dir=ltr>
typedef CString (*GETDRIVECDROM) (void);
GETDRIVECDROM 
GetDriveCDrom;</P>
<P dir=ltr> </P><P dir=ltr>//----------------------
</P>

For Load Dll File , Written this code into OnInitDialog() :

//****************Dll file*********<P></P><P> 
 if(gLibMyDLL != NULL)
 {
  MessageBox("The InfoWindows.Dll Dll has already been loaded");
   return 0;
 }
 gLibMyDLL=LoadLibrary("InfoWidows.dll");</P>
<P> if(gLibMyDLL ==NULL)
 {
  char 
msg[300];
  strcpy(msg,"Cannot load the DLL");
  strcat(msg,"Make sure that the file DLL");
  strcat (msg,"is in your <A href="file://WINDOWS//SYSTEM">file://WINDOWS//SYSTEM</A> directory.");
  MessageBox(msg);
 }</P>
<P> GetPathWindows=(GETPATHWINDOWS) GetProcAddress (gLibMyDLL,"GetPathWindows");
</P><P> </P><P> GetPathSystem=(GETPATHWINDOWS) GetProcAddress (gLibMyDLL,"GetPathSystem");
 </P><P> IsWindowsNT=(ISWINDOWSNT) GetProcAddress (gLibMyDLL,"IsWindowsNT");</P>
<P> GetDriveCDrom=(GETDRIVECDROM) GetProcAddress (gLibMyDLL,"GetDriveCDrom");
//*******************</P>

Continue :

<P>void CUseInfoWindowsDllDlg::OnButtonPathwindows() 
{
 // TODO: Add 
your control notification handler code here
 </P>
<P>   if(gLibMyDLL ==NULL)
 {</P>
<P> MessageBox("You must first load The DLL 
file");
 return;
 }</P>
<P>m_str2=GetPathWindows();
UpdateData(0);</P>
<P> </P>
<P>}</P>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer ArdakanKavosh
Iran (Islamic Republic of) Iran (Islamic Republic of)
I'm from Iran, and Live in Ardakan City.
I'm Computer engineering (HardWare-Software).
I'm Programmer . (VC++ , C++ , Assembly , Basic , C# , Web Programing [ ASP,Php ])

Comments and Discussions

 
GeneralNice... Pin
Aoi Karasu 11-Jan-10 4:38
professional Aoi Karasu 11-Jan-10 4:38 
GeneralRe: Nice... Pin
Behzad Bahjat Manesh20-Jan-10 5:24
Behzad Bahjat Manesh20-Jan-10 5:24 
GeneralWindows in Iran Pin
JonnoB6-Jun-05 8:27
JonnoB6-Jun-05 8:27 
GeneralRe: Windows in Iran Pin
moliate13-Oct-05 12:33
moliate13-Oct-05 12:33 
This article explains a lot:

http://www.iranian.ws/cgi-bin/iran_news/exec/view.cgi/2/3822[^]




The corners of my eyes catch hasty, bloodless motion -
a mouse?
Well, certainly a peripheral of some kind.

Neil Gaiman - Cold Colours


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.