|
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.
|
|
|
|
|
Hi, everyone,
How to load a MFC dll, which itself uses _declspec( dllexport ) type function export from another dll, with using LoadLibrary()? When I use LoadLibrary() to load the dll it always return to me a NULL.
If I comment out the function call to the _declspec( dllexport ) type of function, then LOadLibrary will successfully load the dll. How can I solve this problem? If I use WINAPI to replace the _declspec(dllexport), the compiler will complain me extern function is not resolved.
Thanks in advance.
|
|
|
|
|
Is the manual copying of 'MyDll.dll' to the same folder as 'TestDll.exe' THE ONLY WAY to let the system know where the '.dll' is located? Isn't there some other way by which we could designate to the system where the '.dll' file is located (other than that physical copying of it)?
Also, I was once told that it was not necessary to enter the full path of the '.dll' class (in this example, 'MyClass.h' in the #include statement of the dialog). That there was another way (which I don't recall exactly how at this time).
Other than what I've stated, you did a pretty good job. Keep it up!!
William
|
|
|
|
|
Section A
Manual copying of dll's to target folder in NOT the only solution.
1) You can set the PATH variable on your m/c to include the folder in which the dll is present. Typically the program searches the local directory and then the paths specified by the PATH variable.
2) You can configure you VC++ to 'drop'/create the target DLL into the exe's(application using the dll) folder.
3) Or you can configure VC++ to 'drop'/create the target dll into you operating system's folder or any other folder which is set in the PATH variable.
Use the Project->Settings->Link->General and fill up the output path & file name
4) Just run the DLL project, you should get a dialog asking you to specify the executable name& path , I'm sure you know what to do now.
Now lets see what method is the most suited for a typical application to be deployed
1) Ideally you should not be cluttering up the operating systems folder.
2) You would not want to put your DLL in some vague location, instead you could use a relative path.
Section B
Please take a careful look at the code snippet. Note we have NOT entered the complete path, rather a relative path has been used.
The idea of the tutorial is to keep things as simple as possible and be focussed on developing the DLL and test client and not bother the user abt various deployment scenarios.
Anyways good that you asked...
Cheers...Imran
|
|
|
|
|
Yeah this was a better idea Imran!.
I set the path of the MyDll.dll into ..\TestDll\Debug\MyDll.dll using Project->Settings->Link->General option in the MyDll workspace... and wallah...it clicked.
Good tutorial for beginners (like me)..Infact I got atleast 6 projects of mine using same funcs.. I get a good work on hand to do now..
Thanks a lot.
Scorpion
|
|
|
|
|
Use AFX_EXT_CLASS in the class declaration, in case you wish to export the entire class from your DLL
Richard Lewis
|
|
|
|
|
Could you elaborate some more and perhaps give a little code snippet?
Thanks.
William
|
|
|
|
|
In the header file for your DLL, add the AFX_EXT_CLASS keyword to the declaration of your class as follows:
class AFX_EXT_CLASS CMyClass : public CDocument
{
//
};
|
|
|
|