Click here to Skip to main content
15,030,240 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

My question is very simple. I have created 2 projects:

1) MyApp - MyApp.exe
2) Mydll - Mydll.dll

// Mydll.h : main header file for the Mydll DLL

#pragma once

#ifndef __AFXWIN_H__
	#error "include 'stdafx.h' before including this file for PCH"

#include "resource.h"		// main symbols

// MydllApp
// See Mydll.cpp for the implementation of this class

class MydllApp : public CWinApp

// Overrides
	virtual BOOL InitInstance();



#pragma once
// MydllDlg dialog
class MydllDlg : public CDialog
    MydllDlg(CWnd* pParent = NULL);   // standard constructor
    virtual ~MydllDlg();
// Dialog Data
    enum { IDD = IDD_DIALOG_CRINV };
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

I have created these projects separately.

Now, I want io include this dll to the app so that I can instantiate obj and call methods of the dll from the app.

What are the correct steps I need to do in order to success this.
(Kindly explain in DETAIL the steps as i'm NEW to software development)

If there were already some threats or explaination on this done kindly send me the link.

I have do some searching but, it does NOT HELP me because in those forums the answers were given to ppl who are knowlegeable in MVS IDE. (e.g "reference your dll to the project and import the dll in the project")...seriously I tell you, I don't know how to do that!

Sorry if I'm too harsh :)

skunkhead :)
Updated 9-Apr-11 20:05pm

You do not "include" DLLs. Another name for them is "Shared Libraries". They are linked to or loaded during run-time. They are shared because other MZ file (Portable Executable) can also link or load the DLL from the same file.

Here you can find instruction of how to reference them:[^][^]

As to the loading DLLs dynamically, you really need to know two Windows APIs: LoadLibrary ([^]) and GetProcAddress ([^]). First function return is used as input for another one.

Albert Holguin 10-Apr-11 2:45am
great references sa, my 5
Sergey Alexandrovich Kryukov 10-Apr-11 19:42pm
Thank you, Albert,
Espen Harlinn 10-Apr-11 9:35am
Nice links, 5ed!
Sergey Alexandrovich Kryukov 10-Apr-11 19:42pm
Thank you, Espen.
Take a look at this tutorial:[^]
skunkhead 9-Apr-11 22:56pm
thanks Hans,
Your link was a good one! I'm using Implicit linking.

I'm able to compile the linked App. Perfect!

Now, I need to create an object/instance of the dll in the App class.
What i did:
#include mydll.h //Compile Perfectly!
void CMyAppDlg::OnBnClickedBtnCrInv()
// TODO: Add your control notification handler code here
Mydll test; //Compile error

I'm getting error:
error C2065: 'Mydll' : undeclared identifier
syntax error : missing ';' before identifier 'test'
error C2065: 'test' : undeclared identifier

If i'm not mistaken the way i create the instance is wrong.
May I have your advice on this?
Hans Dietrich 10-Apr-11 0:17am
If you are just trying to call a function in the DLL, then all you have to say is
with the appropriate parameters, of course. Since you haven't shown any code, or said what was in the DLL, this is my best guess.
skunkhead 10-Apr-11 1:22am
is this mean that I no need to create an instance of the dll class?straight calling the dll's function will be fine?

it has MydllDlg.cpp. This will have a dialoguebox with some controls.Not more.
I want the MyAppDlg::OnBnClickedBtnCrInv() to open the dialoguebox of dll.
Hans Dietrich 10-Apr-11 1:47am
It sounds like you have a dialog class in your DLL. Is that correct? If it is, then yes, you have to create an instance of your class. "MydllDlg.cpp" is a filename. This tells me nothing. Does it contain an implementation of a dialog class? Please show the contents of mydll.h.
skunkhead 10-Apr-11 2:06am
I have update the question with the implementation of the header files. Please have a look.
Hans Dietrich 10-Apr-11 3:53am
To shortcut the back-and-forth, I have created a demo that shows how to display a dialog from a DLL, Please download it here:
Please post here if you have questions.
Espen Harlinn 10-Apr-11 6:52am
Nice link, 5ed! :)
Sergey Alexandrovich Kryukov 10-Apr-11 19:43pm
Agree. My 5.
My favourite solution is to use:
 #pragma comment( lib, "mydll" )

It's documented here:[^]

I usually embed the #pragma in the header file, so all that's required is to #include the right header, and the linker has all the information it needs - nice and simple :)

Espen Harlinn
Hans Dietrich 10-Apr-11 9:16am
Yes, I use this too. Since it was a newbie question, I wanted to stick to the basics.
Espen Harlinn 10-Apr-11 9:34am
And I rewarded you a 5 too :)
Hans Dietrich 10-Apr-11 11:38am
Gave you a 5, one of my favorite tricks.
Espen Harlinn 10-Apr-11 11:49am
Thanks Hans :)
Albert Holguin 10-Apr-11 15:25pm
once again... elegant solution.. my 5
Espen Harlinn 10-Apr-11 15:45pm
Thanks Albert :)
Sergey Alexandrovich Kryukov 10-Apr-11 19:45pm
This is very convenient and robust. My 5.
Sorry my ignorance: is is a part of C++ standard?
Espen Harlinn 11-Apr-11 15:07pm
Thanks SAKryukov,
Each implementation of C and C++ supports some features unique to its host machine or operating system. Some programs, for instance, need to exercise precise control over the memory areas where data is placed or to control the way certain functions receive parameters. The #pragma directives offer a way for each compiler to offer machine- and operating system-specific features while retaining overall compatibility with the C and C++ languages. Pragmas are machine- or operating system-specific by definition, and are usually different for every compiler.

Sergey Alexandrovich Kryukov 11-Apr-11 15:14pm
Sure. Thank you for the answer.

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900