|
sugumar wrote:
I define CUserDlg object in MenuDlg header file.
CUserDlg* UserData;
And when I access UserData->szName in CMenuDlg.Cpp file, i get only NULL value.
Where do you assign the original CUserDlg pointer to the UserData pointer. I usually pass the pointer via the constructor, but your code doesn't appear to do that.
Roughly,
UserDlg.cpp
CUserDlg::OnOK()<br />
{<br />
CMenuDlg dlg(this)<br />
dlg.DoModal()<br />
}
CMenuDlg.h
class CUserDlg;<br />
<br />
class CMenuDlg : public CDialog<br />
{<br />
public:<br />
CMenuDlg(CUserDlg* pUserDlg, CWnd* pParent = NULL);
<br />
private:<br />
CUserDlg* m_pUserDlg;<br />
}
CMenuDlg.cpp
#include "UserDlg.h"<br />
<br />
CMenuDlg::CMenuDlg(CUserDlg* pUserDlg, CWnd* pParent)<br />
{<br />
m_pUserDlg = pUserDlg;<br />
}
Then when you want to access szName
void CMenuDlg::SomeFunc()<br />
{<br />
CString temp = m_pUserDlg->szName;<br />
}
Michael
CP Blog [^]
|
|
|
|
|
thanks for your immediate response and which also solves my problem.Tnahk You Michael
|
|
|
|
|
Did you try it to see if you could?
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
As you might know 'new' and 'delete' are C++ keywords for memory allocation and deallocation.
But these small words do more than just memory management.
'new' will call the constructor for the object being created and 'delete' will call the destructor for the object being destroyed. This means that if you create a dynamic object with 'new' and free the memory for that object using 'free', your destructor will not get called and resources allocated by your object will not be freed.
Technically I suppose you could use 'free' given that your class doesn't have to free up any memory in its destructor, but then you have another problem.
When building for Debug some extra bytes will get allocated using 'new' to be able to discover memory leaks and so forth. If you don't use 'delete' at least this memory checking won't work and there is a great risk that the application will crash.
In short:
ALWAYS use 'delete' when you have allocated memory using 'new'.
Using 'free' when deallocating memory allocated using 'new' might work under VERY special circumstances but trying to use this technique would be begging for problems in my opinion.
--
Roger
|
|
|
|
|
Thanks. My 5 marks.
Espically for that Debug build problem.
|
|
|
|
|
I posted the following in the VB forum but nobody seems to be interested (or has the ability to help).
------------------------------------
I've written a DLL in VC6 (C++), and I think it's going to be used by a VB programmer. Knowing this ahead of time, I return variants from all exported functions.
I've tested the DLL with a C++ program, but I don't have VB installed and don't care to install it, so I'm looking for some help from someone that already has VB installed and knows how to use the language.
1) What do I need give the VB programmer in terms of info about the exported functions in the DLL?
2) Can someone here download and try the DLL in a VB program? If so, go here to download the DLL (includes the C++ test program source):
http://www.paddedwall.org/john/programmer/code/d3dlltest.zip
The DLL is designed to find different versions of the racing sim I play on the PC. It does this by looking for specific registry entries. For all but maybe one other person here, the DLL should reveal that none of the sims are installed.
[EDIT]
This DLL is not a COM DLL. It is not an ActiveX DLL. It will never be either of the those. Don't bring it up. Don't suggest it. Don't argue the point, because I'm truly not the least bit interested. I will not treat suggestions along those lines with sensitivity, caring, or kind remindeers. I'm not asking for opinions, different ways to do something, or anything like that. I am asking for facts in response to the questions I posted in this message. You have been warned.
[/EDIT]
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
1) What do I need give the VB programmer in terms of info about the exported functions in the DLL?
The header file should be enough. Note that your exports will need to be in CDECL (assuming your dll is a non-ActiveX one...)
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
The DLL is NOT an activeX(crement) DLL.
I used a def file for exports and did the following for each exported function:
VARIANT PASCAL EXPORT FunctionName()
VB doesn't use header files (that I know of) so that reference kinda confuses me.
As far as I can tell, the PASCAL macro expands out to "__stdcall".
What I need is for someone to try using the DLL from a VB program. All of the exported functions are tested in the sample app enclosed in the RAR file.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
VB doesn't use header files (that I know of) so that reference kinda confuses me.
No - but you can convert the C++ function def from the header file into a VB import declaration.
e.g.:-
<br />
<br />
BOOL SymGetSearchPath(<br />
HANDLE hProcess,<br />
PSTR SearchPath,<br />
DWORD SearchPathLength);<br />
becomes
<br />
Public Declare Function SymGetSearchPath Lib "dbghelp.dll" ( _<br />
ByVal hProcess As Long, _<br />
ByVal SearchPath As String, _<br />
ByVal SearchPathLength As String) As Long<br />
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
John Simmons / outlaw programmer wrote:
I've written a DLL in VC6 (C++), and I think it's going to be used by a VB programmer. Knowing this ahead of time, I return variants from all exported functions.
If you really want to make it easier for VB programmers, build a com dll instead.
|
|
|
|
|
I didn't say I was trying to make it "easier" for VB programmers - I said I wanted to make sure it could be used. I'm a C++ programmer and I'm willing to expend a little effort to ensure that VB programmers can use the DLL, but I'm not going to do it at the expense of making it more difficult to use the same DLL in a C++ program.
I don't do COM unless absolutely necessary. COM is a burden on the system, a hack on the registry, and a lot more difficult to use in C++ (my preferred programming environment).
I gave a nod to the lack of suffient intrinsic types in VB by returning variants, and that's about as far as it will probably go. Now, back to the two questions I originally asked...
1) What do I need to tell the VB programmer in terms of using the DLL?
2) Can someone here that writes VB code try the DLL for me to make sure it in fact can be used in VB?
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote:
I didn't say I was trying to make it "easier" for VB programmers - I said I wanted to make sure it could be used.
Then you don't need to do anything, I am sure it could be used in its original form.
|
|
|
|
|
John,
I've tried to download your dll but the link doesn't work from my current location.
Here is a sample of how I use a dll from VB. (I just ripped the first one from a VB project). This one gets the GetFileVersionInfoA function from Version.dll.
Declare Function GetFileVersionInfo Lib "Version.dll" Alias _<br />
"GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal _<br />
dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long
So basically, all you need to provide to your VB programmer, is the dll name and the parameters for each function. If you sort the link or send me the files, I'll give it a go. (However my current machine doesn't have anything to unrar anything, so zip format would be better)
Michael
CP Blog [^]
|
|
|
|
|
Dang. I wish I had seen your message before I left for work. I have to fix it from home... :/
I'll see what I can arrange here, but I can't rightly know if I remember the password to my ftp account.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Okay, I changed it to a zip file and the link in the original mesage is correct now.
BTW, the sample C++ app is dialog based and displays the install status of each sim in a list box. If you need more info on the DLL, let me know.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hmm. I can't seem to get it to work.
Private Declare Function vbGetDllVersion Lib "D3SimInstalled" Alias "GetDllVersion" () As Variant<br />
<br />
Private Sub Form_Load()<br />
Dim ver As Integer<br />
ver = vbGetDllVersion<br />
Debug.Print ver<br />
End Sub
is returning 0 for the version number. The rest of the functions are returning empty strings.
Michael
CP Blog [^]
|
|
|
|
|
Hmmmm...
Does VB automatically cast a variant to the variable's defined type?
Could I have my export macros implemented incorrectly?
I'm using this
VARIANT PASCAL EXPORT FunctionName()
and the def file has the function name in the EXPORTS section, and the C++ sample works fine.
:/
Any suggestions on what to check?
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Could it be that I don't have the ordinals in the def file?
I have this:
FunctionName
instead of this:
FunctionName @1
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I'm no expert on this. I usually do most of my VB/VC++ communicating via COM.
My first thought is that the data has simply gone out of scope. I'm back on my main machine now, so I'll try again and see if I get different results. I'm tempted also to try with VB.NET and see if that performs the same.
Of course, the easiest way to track down the problem is to debug into the dll from the VB call - but you'd have to install VB6 to try that
Michael
CP Blog [^]
|
|
|
|
|
How about if I convince you to create a simple sample app in vb that does pretty much what the c++ sample does, compile it and email it to me?
When it works, I'll know my DLL is tits.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote:
How about if I convince you to create a simple sample app in vb that does pretty much what the c++ sample does, compile it and email it to me?
Yeah. That's not a problem. It'll take me some time but I can do that. The only bitch is that ListViewCtrl is a pain to use in VB, but I'll get is stored for you.
Michael
CP Blog [^]
|
|
|
|
|
Would a multi-line edit field be better with each string on it's own line?
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Ignore everything I've said. I've retried your dll and all the string functions are returning correct values. The version number is wrong though. It is being returned empty.
I'll finish up the app so you can test but everything seems okay now apart from the version.
Michael
CP Blog [^]
|
|
|
|
|
That's great news.
I wonder why the version number wouldn't be working...
Can I get the source to your sample app as well? I would like to provide it in the zip file so that VB programmers won't be bothering me too much.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I've emailed you the app and the vb project too. Let me know if you don't get it.
Michael
CP Blog [^]
|
|
|
|