|
How do I create a dialog in a dll?
I have a dll that exports the following function:
void MsgBox()
{
CMessageBox dlg; // CMessageBox inherits from CDialog
dlg.DoModal();
}
When I call this function from my main app I get an Assert error. Why??
I'm kind of new to vc++/mfc/win32 =)
/ombak
|
|
|
|
|
Rewrite like this
void MsgBox()
{
CMessageBox dlg(AfxGetMainWnd());
dlg.doModal( );
}
cexoxtdc
|
|
|
|
|
I tried adding the AfxGetMainWnd()) but I still get the assert
I am new to DLL's actually I am trying to create my first. My project is becoming to big, and would like to create a dialog in a dll.
My exported function looks like this:
In my cpp file
#include "General.h"
...
...
void CMyClass::ShowClientsFrm(CString WhoCli)
{
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
CGeneral ClientFrm(AfxGetMainWnd());
ClientFrm.ShowWindow(SW_SHOW); // Assert error
}
CGeneral is derived from CDialog
What am I doing wrong?
|
|
|
|
|
Hi!
Why do you call the .ShowWindow function? You didn't create a modelles dlg. You have to call the .DoModal ( ) or to create your dlg with this code:
CGeneral *dlg = new CGeneral ( );
dlg->Create (IDD_XXX, this);
dlg->ShowWindow (SW_SHOW);
Regards
G. Clarence
|
|
|
|
|
Hi, I'm kinda a beginner in MFC.
I was wandering, is it possible to write a DLL for an application that we don't have access to the source code?
|
|
|
|
|
Thank you very much for this article, it has been of great help. Now I need to import the DLL that I have created VC++ in order to use them in Basic, this is done through the References, but it says error,even if I import it from MyDLL.dll... if you could help me I´ll be pleaced
Thanks for your time
el hombre es libre cada vez que elige y eso es lo que lo hace libre
el hombre arriesga su vida cada vez que elige y eso es lo que lo hace libre
|
|
|
|
|
I had created a dll file using vstudio win32 dll without the support of MFC. While calling the function in dll from a vb app., an error comes telling the entry point to the function is not found. I had used __declspec(dllexport) for the prototype of calling function. Still no sollution. Can any one help me out?
|
|
|
|
|
The functions calling conventions are not the same in VB and VC (for more info, take a look at calling conventions topic from the MSDN).
You have to specify that the functions you put in the dll use the standard calling convention (the one useb by VB).
You can do this using the __stdcall keyword:
__declspec(dllexport) int __stdcall YourFunction();
You need also to add a .def file in your project wich will contain the list of the exported functions. A typical .def file looks like:
; YourDLL.def : Declares the module parameters for the DLL.
LIBRARY "YourDLL"
DESCRIPTION 'YourDLL Windows Dynamic Link Library'
EXPORTS
; Explicit exports can go here
FunctionName1 @1
FunctionName2 @2
So, you just have to specify the names of all the exported functions.
|
|
|
|
|
Hello Cedric Moonen!!
Thanx for your comment. But I tried what you said, but it didn´t work... appear the same error message.
I did:
; MyDll.def : Declares the module parameters for the DLL.<br />
<br />
LIBRARY "MyDll"<br />
DESCRIPTION 'MyDll Windows Dynamic Link Library ;)'<br />
<br />
EXPORTS<br />
; Explicit exports can go here<br />
SayHello @1<br />
and
class CMyClass <br />
{<br />
public:<br />
__declspec(dllexport) CString __stdcall SayHello (CString strName);<br />
__declspec(dllexport) __stdcall CMyClass();<br />
__declspec(dllexport) virtual __stdcall ~CMyClass();<br />
<br />
};
what happend?
el hombre arriesga su vida cada vez que elige y eso es lo que lo hace libre
|
|
|
|
|
i've gone through the article by Mr Imran, "Creating and consuming MFC DLLs for Beginners" But he is using Generic class , not derived class. I want to export a function that belong to a class derived from CWnd class. It gives error message "starting point not found" while running.
please help.........
pranab kumar bharimalla
|
|
|
|
|
I try this project with "USE MFC in a static Library".
It will crash when call the DLL. why?
Env: VC++ 6.0 SP5, Windows 2000 SP3
|
|
|
|
|
Hi,
Thanks for your wonderful tutorial. It helps me a lot.
Anyway, I'm still not clear about __declspec( dllexport ) and __declspec( dllimport ).
At first, I think I need to import dll for the client app, but after reading your tutorial, it seems not necessary to use import thing.
It would be great if you clarify my thought.
Many thanks
Jiji
|
|
|
|
|
I'm a beginner and i like programming with VC++ ,specially(OCX & DLL programming)
as you know It is nice to be able to make a DLL project that includes its own resources (such as a dialog resource) and then be able to call it from another project.
How could i call a DialogBox from DLL(dynamic link library)?
Please help me.(if possible please send me a free source code!!!)
|
|
|
|
|
Just add AFX_EXT_CLASS macro to the class declaration. i.e.
class AFX_EXT_CLASS myDialogClass
{
...
};
|
|
|
|
|
great piece of work, i have been looking for some good pointers on dlls, one big question, is it possible to play a wav file stored in the dll?, i can load a icon or bmp but am totally stumped in sound, any helps appreciated.
shotgun
|
|
|
|
|
To play a wav from the dll, first insert ur wav file into dll's resource (Insert->Resource, click Import, select file, choose resource type name, then rename resource with a string name ("MySound")),
then each time you will need to play it, extract resource to the temporary folder, play it, then delete when finished.
Here's the code to extract resource:
<br />
void ExtractRes(CString FileName, CString Exe, CString ResName, CString ResType)<br />
{<br />
HRSRC hRes;<br />
HMODULE mdl;<br />
HGLOBAL mem;<br />
HANDLE file;<br />
LPVOID pData;<br />
<br />
mdl = ::GetModuleHandle(Exe);<br />
hRes = ::FindResource(mdl, ResName, ResType);<br />
mem = ::LoadResource(mdl, hRes);<br />
pData = ::LockResource(mem);<br />
<br />
<br />
file = CreateFile(FileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);<br />
DWORD dwBytesWritten = 0;<br />
DWORD dwDataSize = ::SizeofResource(mdl, hRes);<br />
::WriteFile(file, pData, dwDataSize, &dwBytesWritten, NULL);<br />
::CloseHandle(file);<br />
::UnlockResource(mem);<br />
::FreeResource(mem);<br />
<br />
return;<br />
}<br />
I re-wrote this code to make it work with all applications, so i didn't test it yet
|
|
|
|
|
How can I dynamically load a dialog from an MFC extension dll?
|
|
|
|
|
Hi
I'm totally new to DLL projects but recently i need to make use of it in my project. Below are some of the queries that i have and I hope you can help me with it.
1) Can I interface my project (written in VC++6) to activate the OCR function given by the scanner?
2) If this can be done then which DLL should I load? (there are a lot of DLL files given by the HP scanner software)
3) How do I know what functions a particular DLL possess?
Thx for your help
|
|
|
|
|
1) Yes you can interface with a printer or any device... via serial port programming or using API's provided by device vendor
2) You would need to refer to your printer guide or maybe check out HP site for more details.
Imran
|
|
|
|
|
Its very helpful article for beginner like me.
Thanks ;
Kedar
|
|
|
|
|
Hello,
I am new to dll programming. My question is relatively straightforward:
Can a dll contain a main function or dlls are simply meant to be a repository of functions used by an exe. Or to put it another way is the following true?
dll = no main function
exe = main function
Thanks in advance,
Julien
|
|
|
|
|
Your thinking is on the right path. DLL are in process which means they have to be loaded by another program to be executed.
If your thinking about invoking the dll function like you do for command line programs it is possible by using the rundll32.exe program that ships with windows.
|
|
|
|
|
I have a very strange problem and I really don't know how to solve it.
I created a DLL that exports some classes. One of the classes is CGLSocket (yeah, you guesed right, it's a socket class). Because my app that uses this class started to crash I debuged this file and found something strange.
If I write:
CGLSocket socket;
int k = sizeof(socket);
then k is 645.
Buf if I write :
k = sizeof(*this);
inside of CGLSocket class I get k = 652.
So obviously I get different values for the same thing.
Even more strange is, that I tried the same DLL in a different app and it works fine (and also sizeof() returns the same value )
Help, please... I'm lost.
|
|
|
|
|
Hey I tried to reproduce the problem, but everything seems to be working just fine. Maybe you should try giving more details
|
|
|
|
|
Thanks for writing this one I've been looking for a very simple DLL tutorial!
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|