|
ok so you look at step 11: it says tht you are changing the settings for the project to execute the dll.
so:
when you first created the dll project, you need to have built/debuged it in the other computer you said where you wanted the dll. the .lib file tht step 11 asks for will then be created in the network pc. so you need to male a direct link to the file on the network pc to the local pc. i suggest dragging the whole project folder (of the dll on the network pc) to shared documents, then on your local pc, create a network drive and link it to that shared documents on the network pc. the drive should show up on that pc. (remember what letter you gave it. so then you go bck to the project>link properties for the app on your local pc and provide the path for the .lib in the dll pro folder. lemme show you an example:
if the network drive is S,
then the path would be s:\MyDll\Debug\MyDll.lib
where s being the network drive you created to link to the shared doc on the network pc and MyDlll being the project folder
hope this helps
Jay
|
|
|
|
|
Hi,
I have a C# DLL and I need to use id in dialog box.
Is anyone have an idea about how to do it, please?
Thanks
|
|
|
|
|
Thanks Chris for this article, but I have a problem:
I've a dialog in a DLL. I tested it from a client application and it works fine. But if I include in the dialog the Microsoft FlexGrid 6.0 control (an ActiveX component) the dialog isn´t created. Te control is associated to a variable, and the dialog works fine if it is in a .exe file, not in the .DLL!
Can anyone help me?
thanks
ActiveX in DLL
|
|
|
|
|
Hi, you raised a very good question. Unfortunately, I did not see any relpies to your question. Is there any solution? I am currently struggling with the same problem. If you have had it fixed, would you please kindly let me know?
Thanks,
Wenjun
|
|
|
|
|
Hello Wenjun
You can see the same question, the author's replies, and the solution in http://www.codeproject.com/dll/The_DLL_Hell.asp
|
|
|
|
|
Hello LuisM,
Many thanks for your quick reply. It helps a lot and exactly solves the problem -- An Excellent Solution!!!
Thanks again,
Wenjun
|
|
|
|
|
Nice to help you.
|
|
|
|
|
Hello, i have a problem, MyDLL example run ok but, when I tried to buil my TestDLL.exe, i get a error thath said that can not find C:\Program.obj", and I cant make the exe. I dont know if is a error for my program or is something with my computer.
I have Windows 2000 profesional.
Thank you
Iliana Rodriguez #46033
|
|
|
|
|
The problem is the WHITE SPACE
Ortosys
|
|
|
|
|
Hi,
this looks fine. but I got an error message on running. First there is no error on compiling the DLL in Debug mode, but there are 3 warning in Release mode:
all references to "ADVAPI32.dll" discarded by /OPT:REF
all references to "SHELL32.dll" discarded by /OPT:REF
all references to "comdlg32.dll" discarded by /OPT:REF
then on the test dialog project, there is no error compiling on Debug (with link to Degub directory for the lib DLL's project) nor to the Release version (with link to the Release Dir. for the DLL's project). For each I put the proper .dll file in the Debug or Release directory of the App's project.
The project is running fine, the popup apears with the "hello [whatever]" but right after, there is a crash. What do I am doing wrong?
thanks
Mat
|
|
|
|
|
This article is top banana! However, I have a technique for writing really easy DLLs in VC++ that is guaranteed to work in either other VC++ progs OR Visual Basic. Takes about 5 minutes, seriously. Lots of posts here (specially the one regarding VB problems) have covered this to some degree, but there are a few errors in the solutions - plus there are easier ways than those listed here.
I'm an IT consultant and have to do this sort of thing quite often. Please send me an email if you want me to post the technique here as I don't want to waste anyone's time or teach any grannies how to suck eggs.
Cheers,
Chris.
chris.nixon@logicacmg.com
|
|
|
|
|
Ok, this is the technique, as requested by Harry who emailed me this afternoon. Hope this isn't a let-down! All I can guarantee is that you will be able to call the DLL successfully from other VC and VB apps...
First up I should state that this is done in VC++ 6.0 but it is so bare-bones it should work in earlier versions (at least from 4.0 up).
First, fire up the AppWizard and choose 'Win32 Dynamic-Link Library'. Enter a name for your DLL project, such as MyDLL, choose a folder and click OK.
On the next screen of the Wizard, which asks which type of DLL you would like, choose 'A DLL that exports some symbols', because this provides some template code we can modify (and dump the bits we don't need), and click Finish. For the technically-minded, this option will add exports for one class, one variable and one function. It is the function we are after.
Click OK on the final Wizard screen to confirm your choices and our skeletal DLL is built. Now we need to customize it - but it's really, really easy.
We'll customize it so that the DLL contains one function named 'AboutBox()', which displays a simple MessageBox when called from your client application. This gives you an easy way to confirm you are accessing the DLL properly.
First, click on the FileView tab. Expand all the tree nodes so you can see the source and header files. Double-click 'MyDLL.h' or whatever the main H file in your project is called. Delete the comments at the top (optional), then delete all the lines following the #endif EXCEPT for the last line in the file - this last line is the one and only function created for you by AppWizard, and we will customize it shortly.
The file should now look like this:
MyDLL.H
----------------------------------------------
#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif
MYDLL_API int fnMyDLL(void);
----------------------------------------------
Now save your work, and double-click 'MyDLL.cpp', or whatever the main CPP of your project is. Underneath the definition of the DLLMain() function are the definitions for the same three items we just altered in the H file, and we need to alter them here too. Remove the definition for the exported variable and the exported class. Leave the exported function. The bottom bit of this file (I won't repeat the MyDLL class definition here) should now look like this:
MyDLL.CPP
----------------------------------------------
// This is an example of an exported function
MYDLL_API int fnMyDLL(void)
{
return 42;
}
----------------------------------------------
Almost there. We now have a pretty naff function that does not do a lot. That will change. Go back to the MyDLL.H file and alter the function definition for fnMyDLL() until it looks like this:
MyDLL.H
----------------------------------------------
MYDLL_API int __stdcall AboutBox(void);
----------------------------------------------
Go back to MyDLL.cpp and alter the function definition of fnMyDLL() to look like this:
MyDLL.CPP
----------------------------------------------
MYDLL_API int __stdcall AboutBox(void)
{
return MessageBox(NULL, "My First DLL", "About MyDLL", MB_OK);
}
----------------------------------------------
Now we need to add a .DEF file (so it works in VB - we don't need this step if we aren't using VB to call the DLL). Click the 'New File' toolbar icon and type the following exactly as it is here (well you can type what you want for the description), and save it as 'MyDLL.DEF' :
MyDLL.DEF
----------------------------------------------
LIBRARY "MYDLL"
DESCRIPTION "MyDLL Dynamic Link Library"
EXPORTS
AboutBox @1
----------------------------------------------
You need to add this file to the project, so right-click on the node 'Header Files' in FileView and select 'Add Files to Folder'. In the Insert Files into Project dialog, click on the 'Files of Type' drop-down and choose 'Definition Files (.def)'. Your new MyDLL.def file should now be visible so double-click on it.
Now you are ready to compile your DLL. Don't forget to select 'Release' mode! And don't forget to save your work first!
To use the DLL from another VC++ program, do the following:
Create an MFC (or whatever you prefer) EXE in AppWizard. Make it a Dialog-based application as it's easier to follow the next step.
Place a new button on the dialog form. Double-click the new button and you will be prompted to create a member function named 'OnButton1' or similar, depending on whether you changed the resource ID from its default. Click Ok. In the new function body, type the following under the comment line:
// TODO: Add your control notification handler code here
AboutBox();
Save and close the project because you need to copy some bits over from the MyDLL project before it will compile.
So, first copy the actual 'MyDLL.dll' file from the Release sub-folder of your MyDLL project folder, into the Release sub-folder of your new VC++ project. Then, also from the DLL's Release folder, copy the file 'MyDll.lib' but this time to the source code folder of your VC++ project - this is because we want to link to this file in a moment and it's easier not to have to worry about pathnames. Finally, copy the main header file from your DLL project, 'MyDLL.h', over to the source code folder of the new project.
Now, re-open the new project. At the top of the CPP file where the new OnButton1() function was added by ClassWizard, add the following line:
#include "MyDLL.h"
Now, click on the Project menu. Select Settings, then click on the Link tab. In the text box labelled 'Object/Library modules', type MyDLL.lib and click Ok. Remember to make sure you are in Release mode first because we put the DLL in the Release subfolder and the IDE keeps different Link settings for Debug and Release modes.
Compile your app (again, make sure you are in Release mode) and run it. Click the button on the dialog and bingo! A small About box will appear.
To call your DLL from VB, you will beed to add a 'Declare' statement at the top of your VB project:
Public Declare Function AboutBox Lib "MyDLL" () As Long
That should do it. I'm no VB coder and I can never remember the syntax but one of my VB colleagues just this morning did just this to access one of my DLLs written in the above manner. I'm sure other VB experts here can help if I have got this line wrong!
I hope I haven't missed out any steps. Basically the DLL is easy to get working in VC programs. But for VB, you need to remember two things; the __stdcall function modifier, and the .DEF definition file.
Have fun and let me know if you get results, one way or another. I promise to reply to any posts where problems are experienced.
PS - to add more functions to your DLL, add their prototypes to the H file and their definitions to the CPP file - and don't forget to add an entry to the .DEF file, use @2, @3 etc as you add more and more.
Cheers,
Chris.
|
|
|
|
|
Chris,
Thank you - it worked first time and was as easy as you had said!
I have also passed strings into a function which I needed to be able to do. I now need to cut my old C program up and make it into functions that can be called by vb ... I am sure that I will have lots more questions and problems on the way - but I am started
|
|
|
|
|
Ok, great!
I really need to get this example working but with explicit dll function loading... that is with LoadLibrary and GetAddress. Can you show me what to change in the client so that I can call the function explicitly?
Thx,
/Tommy
|
|
|
|
|
Tommy,
I'm not sure why you need this info - the whole point of this 'articlette' was to show people how to write quick'n'dirty DLLs that you could use in VB or C++ projects without having to use LoadLibrary() and GetAddress().
I wrote this post after seeing that other articles were unnecessarily complex, as I have been writing DLLs professionally for years this way and VB programmers use them with no problems, and I am able to use them in my other C++ projects.
I'm really sorry but you'll have to scan other threads if you want to go this route, as this isn't something I have much experience with...I tend to avoid unnecessarily complex solutions if there's a quicker way, but of course I don't know your circumstances - you may have no choice, but if so I can't really help!
Thanks for reading my post though!
Chris.
|
|
|
|
|
Thanks Chris
Your technique how to access Dlls in VB easy way works great.
|
|
|
|
|
Thank You
That Works.
It Saved a whole lot of time!
Neil
|
|
|
|
|
What can I do if I haven't the head file associate to the specific DLL?
|
|
|
|
|
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?
|
|
|
|
|