|
Hi.
I am learning DLL creation and implemention from Programming Applications for Microsoft Windows by Jeffrey Richter. Richter demonstrations are straightforward and appear simple. However, I cannot implement a working at all using Visual C++ .NET.
I tried using the DLL Wizard and hardcoding a .cpp and .h file. Neither method worked. I would like to create a simple dll with functions I can use in any C++ programs I work on including MFC. In fact, all my Windows program are MFC. Here is an example of the code.
-----
// myDLL.h
#ifndef myDLL
#define myDLL extern "C" __declspec(dllimport)
#endif
class myDLL MyClass
{
MyClass();
void FunctionOne();
int FunctionTwo();
~MyClass();
-----
-----
// myDLL.cpp
#define myDLL extern "C" __declspect(dllexport)
#include "stdafx.h"
#include "myDLL.h"
MyClass::MyClass()
{
}
...
-----
The code above uses the exact sample algorithm Richter presents in his book. It is does not work. I would like a good solid working example of creating a dll that works in both MFC and non-MFC Windows programs.
Thanks,
Kuphryn
|
|
|
|
|
Try this:
1. open a new 'MFC AppWizzard (dll)', choose project name. >>> NEXT
2. Choose 'MFC Extension DLL (using shared MFC DLL)'. >>> FINISH
3. Add to project your classes ('*.h' + '*.cpp').
4. Add AFX_CLASS_EXT macro before your class name definition:
class AFX_EXT_CLASS CYourClass
{
public:
void Method1();
};
5. After compiling a Release version, Pick out of the 'Release' folder
2 files: 'YourDLL.dll' + 'YourDLL.lib'.
6. In the project you wish to use'em, paste in its dir both of'em, and add
to the project 'YourDLL.lib' + 'YourClass.h' (with AFX_EXT_CLASS)
7. Compile and pray...
8. Please reply if this works well.
9. Succsess....
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
Okay. Thanks.
I will try your solution. I do have a question too. I thought when you create a DLL, the compiler produces just one simple DLL file in the release version. How come you mentioned a .lib and .h file?
Kuphryn
|
|
|
|
|
Okay. Thanks.
CheckAbdoul posted a link at MSDN Newsgroups.
http://www.flipcode.com/tutorials/tut_dll01.shtml
That tutorial helped me.
The tutorial he gives helps me considerably. I am confused at the point where the compiler produces a .dll, .lib, and .h file.
For implicit implementation, you have to including the .h file in the source code and import the .lib file. I do not quite understand that process. I believe the compiler only produce a .dll file and you import that file in your source code only. However, I learn that is true for explicit implementation.
Well, explicit implementation is quicker because you do not have to search for the .h and .lib as well as .dll file. Nonetheless, both implicit and explicit implementations are essential.
Kuphryn
|
|
|
|
|
Okay. I just cannot get the compiler to compile the dll without errors.
I have uploaded the entire dll project to my website. Please check it out and see if you can determine the error. I use the exact same technique Jeffrey Richter shows in his book. However, the compiler saying a .pch file cannot be found. Second, I do not understand why Visual C++ includes the stdafx.h file in all projects.
http://www.dslextreme.com/users/kuphryn/software/FirstDLL.zip
Please post if you find an unconditional working solution.
Thanks,
Kuphryn
|
|
|
|
|
Okay. I finally fixed the problem with help from Dean Harding of GameDev.
One more questions.
Here is one working DLL declaration.
-----
#if defined(FIRSTDLL_DLL)
# define FIRSTDLL extern "C" __declspec(dllexport)
#else
# define FIRSTDLL extern "C" __declspec(dllimport)
#endif
-----
I am able to compiler the DLL using this code too.
-----
// FirstDLL.h
#ifndef FIRSTDLL_H
#define FIRSTDLL_H
#define IMPORT __declspec(dllimport)
#define EXPORT __declspec(dllexport)
#ifdef __cplusplus
extern "C"
{
#endif
class EXPORT myClass
{
...
};
#ifdef __cplusplus
}
#endif
#endif
-----
Is there an advantage one declaration has over the other?
Thanks,
Kuphryn
|
|
|
|
|
Hello,
I have a dialog bar that contains the following SliderCtrl message handler:
OnCustomdrawSliderProg(NMHDR* pNMHDR, LRESULT* pResult)
Inside this handler, I call another function to update a 2nd dialog bar's windows. However, when this occurs, the slider control is randomly (time) redrawn on the 2nd dialogbar's client area at random places. I assume I'm mixing device contexts somehow.
Functionally I want my 2nd dialog bar to have a 'live' response to a user adjusting the CSliderCtrl on the 1st dialog bar. Has anyone a solution for a clean way to do this? I've tried to handle the lose-focus SliderCtrl message (works without odd slider drawing), but then if the user uses the arrow keys, the 2nd dialog bar is not updated.
Thanks!
JennyP
|
|
|
|
|
JennyP wrote:
Functionally I want my 2nd dialog bar to have a 'live' response to a user adjusting the CSliderCtrl on the 1st dialog bar
Handle WM_HSCROLL - this message is sent whenever thumb is moved using mouse/keyboard. When user releases the mouse, you'll get WM_HSCROLL with TB_ENDTRACK code. You'll also get TB_ENDTRACK after each keypress changing thumb position.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Hi Anyone and Everyone,
I would like to know how to develop a Code Completion control (similar to that in Visual Studio - Intellisense) and such available in almost all popular code editors. I am not able to find such info. anywhere. If you can't help directly, plz direct me to some place where i may find some resources to help me atleast !
I do hope I get a quick reply
Deepak
|
|
|
|
|
Hi,
I've a function in CMainFrame class which shows a progress bar in the status bar.
<br />
void CMainFrame::showProgress()<br />
{<br />
<br />
RECT MyRect;<br />
m_wndStatusBar.GetItemRect(1, &MyRect); <br />
m_ctrlProgress.Create(WS_VISIBLE|WS_CHILD, MyRect, <br />
&m_wndStatusBar, 1); <br />
<br />
m_ctrlProgress.SetRange(0,100); <br />
m_ctrlProgress.SetStep(1);
<br />
<br />
for (int I = 0; I < 100; I++)<br />
{<br />
Sleep(10);<br />
m_ctrlProgress.StepIt();<br />
}<br />
}<br />
Now, I wish to access this progress bar from my CView class.
This application uses sockets and whenever I receive a new message I wish to show the some activity in the progress bar.
|
|
|
|
|
AfxGetMainWnd() returns the main window, you just need to cast it to be a CMainFrame.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
(Newbie-Warning!)
Hi,
Is there anyone that got a short sample code on how to edit/modify the contents of an external binary file at an exact position?
I've read some articles on how to modify ASCII files, but when it comes to binary files and modifying data in an exact offset location (like a hexeditor)... I'm stuck...
Regards,
Johan
|
|
|
|
|
fopen(filename, "wb");
fseek(pos, offset);
fwrite(data, size, count, filePointer);
fclose(filePointer);
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
Thanks for your quick help!
I'm now heading for my keyboard to try it out!!
/Johan
|
|
|
|
|
If I have a class A, I can also create a class within it called B. Is there any practical use for this? To illustrate my question I will give an example.
<br />
class A<br />
{<br />
int m_nMemberOfA;<br />
<br />
class B<br />
{<br />
public:<br />
void MethodOfB();<br />
};<br />
};<br />
<br />
...<br />
<br />
void A::B::MethodOfB()<br />
{<br />
...<br />
}<br />
Can B gain access to the member variables of A or anything like that without having to pass the "this" pointer?
Thanks in advance,
Clint
|
|
|
|
|
clintsinger wrote:
Can B gain access to the member variables of A or anything like that without having to pass the "this" pointer?
No, of course not. What would happen if they both had an int called a ?
You'd encapsulate one class within another if it existed solely as a helper for that class, if only class A had a need to create instances of class B. Then you could make it private or protected in class A, and control the fact that only class A could make them.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
I think your question is, are nested classes in C++ like inner classes in Java? The answer is no. Offhand, I'd say they are much like static nested classes in Java.
The purpose of nested classes is to express scoping of names.
|
|
|
|
|
Does anyone know how to write data to cd-r drives using IoControl codes in the platform sdk??
|
|
|
|
|
The fact that several expensive SDK's exist to do this suggests to me that it is not an easy task.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Check out the Image Mastering API (IMAPI)
available now under WinXP.
|
|
|
|
|
Was going to use that but it only works on XP not 2000/me/98 etc..
Thanks
|
|
|
|
|
Why have you asked this question three times ?
I'm fairly sure there is an example on the site. The app wizard also creates an app with one splitter, it should not be hard to increase the count to support four views, I would think.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
I also try to find this on the site, but I can't got it. Could you mind tell me where can i find it?
|
|
|
|
|
I dunno, I thought I'd seen it. Maybe it was in MSDN.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
hello Everybody,
I am working on a project involving PCs as peer sensors on a network. The sensor can use ccd cameras (microscops), can process acquired images, can replicate data on an overlay network (P2P), can distribute processing (actually start, control and stop them remotely).
I'd like to create a object-oriented, component-oriented "generic" framework in C++... for sensors in general and for my application in particular. Also, I'd like to have some functionalities (Input, Processing, Networking...), as independent components, i.e. that can be used without the others (separate DLLs?).
Sensor Component
|
|- Input Component
|
|- Processing Component
|
|- Networking Component
|
|- Coordinator Component
MySensor Component : inherited from Sensor Component
|
|- Vision Component : inherited from Input Component
|
|- MyProcessing : inherited from Processing Component
|
|- P2P : inherited from Networking Component
|
|- MyCoordinator : inherited from Coordinator Component
How do I make such a framework? What tools are the easiest?
Where should I start?
Should I buy a book "creating our own framework for dummies"?
Any comments are welcome!!
Thanks a lot!
Bertrand Boichon
Research Assistant
Electrical & Computer Engr.
Oregon State University
|
|
|
|