|
I want to know, what are the typical differences between C++ Classes and Structures. All of us knows that, there is a main difference between the default visibility of parameters/methods [Private and Public]. Apart from this, are there any differences? Like memory allocations etc..
|
|
|
|
|
this question has been asked last week on the C++ forum (as it is a pure C++ question, it has nothing to do on the Managed C++ forum).
consider in basics that in C++, a struct is a class which default members are public...
see here[^]...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Ok, my last post was just too big. I'll try to shorten it here. I'm trying to load DLLs dynamically using the LoadLibrary/GetProcAddress method. What I want to do is call a function in the DLL that creates an instance of the class I need. However I am getting an error:
System.Runtime.InteropServices.MarshalDirectiveException in Unknown Module
PInvoke Restriction: can not return variants
I'm not sure what is wrong, but it seems to be a problem with the variable.
The function looks like this:
Object __gc * __cdecl Build()<br />
{<br />
LeetTrans * a = new LeetTrans();<br />
return a;<br />
}
The head of LeetTrans looks like this:
public __gc class LeetTrans : public Wompi
And the head of Wompi looks like this:
public __gc class Wompi : public System::Windows::Forms::GroupBox
Now for the loader code,
typedef Object __gc * (__cdecl *Builder)();<br />
Builder build;<br />
FARPROC holder;<br />
Object __gc * wompi;
Here's where we cast the function and simply call the function to Wompi:
build = (Object __gc*(*)()) holder;<br />
wompi = build();
This is where our error occurs. So I'm guessing I'm losing the variable somewhere along the way, but I don't know where to begin. Any help would be greatly appreciated. Thank you.
-- modified at 18:23 Monday 28th November, 2005
|
|
|
|
|
Bobamagoo wrote: I'm trying to load DLLs dynamically using the LoadLibrary/GetProcAddress method.
If these are managed types, why don't you use reflection, which is the right way to do this?
|
|
|
|
|
I'm not sure exactly what you mean by reflection Mr. Sivakumar. Could you elaborate?
|
|
|
|
|
|
Wow.... thank you so much. I was REALLY doing things the long way. Now I might actually get to sleep tonight.... I'll also never have those 20 hours of my life back. But at least I'll get to sleep tonight.... mmm.... sleeeeeeeeep......
|
|
|
|
|
I have a Form and i have included:
public ref struct Language<br />
{<br />
String ^strFlagFile;<br />
String ^strLangFile;<br />
};
When i include any struct in same file as a form, then my VS2005 got error in design mode:
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.
Where can i define struct to use in the Form.
ps: I hope that was clear. And Thanks in Advance
|
|
|
|
|
It's safer not to add code to the cpp/h files that are directly modified by the Forms designer. Try and declare your struct in a header file and #include it in your form file - that should help avoid this problem.
|
|
|
|
|
Hi,
I have a SDI app to which I need to add a second fixed toolbar positioned to the right of the first one. Does anyone know how to do this?
Thanks for any help,
Royce
|
|
|
|
|
Try this :
RecalcLayout();
CRect rect;
m_wndToolBar.GetWindowRect(&rect);
rect.left++;
DockControlBar(&m_wndToolBar2,AFX_IDW_DOCKBAR_TOP,rect);
|
|
|
|
|
Thanks, Nishant, for the help. However, the rect parameter is apparently ignored. This always docks the 2nd toolbar under the first one against the left frame border.
|
|
|
|
|
I'm just learning threading and have a question about the safety of calling functions from threads. This is more of a C question rather than C++ but here goes...
What would happen to this function if it was called from thread 01 with arguement 100, then 5 seconds later thread 02 calls it with arguement 101?
Would each thread get back the value it passed or would gremlins creep in and mess everything up?
int myFunction(int myInt)<br />
{<br />
int a = myInt;<br />
Sleep(10000);<br />
return a;<br />
}<br />
BTW... Yes i can try this myself and it seems to work for trivial examples... However is there any reason why it would/should/could not work.
Many thanks,
Daniel
-- modified at 18:40 Sunday 27th November, 2005
|
|
|
|
|
of course it works! Thread safety refers in general to sections of code accesing the same data. So in your case the data int a is internal to the function, thus, each instance of the function (each thread) will be operating on internal data. Your example wouldn't be thread safe if it were accessing let's say a variable int globalA defined outside the function such as:
<code>
int globalA;
int unsafeMyFunction(int myInt)
{
globalA = myInt;
Sleep(10000);
return globalA;
}
</code>
The example above is a quite simple one and you can find more information on the web about concurrency and race conditions and the ways to handle these situations and of course, the issues that arise from trying to avoid them.
|
|
|
|
|
I have a class and i when it comes to certan error, i want my class to close entire process. Can anybody help. I am using VS2005.
|
|
|
|
|
#include <stdlib.h>
if(errHasOccured){exit(0);}
|
|
|
|
|
#include "stdlib.h" //this should be in triangle brakets
if(errHasOccured){exit(0);} //or substitute your error code where the zero is
|
|
|
|
|
I have tryied that and it doesn't work. I am asking for on MC++ forum, so i expect to get managed anser. i have also try using ExitProcess command, but when i include windows.h my compiler complains abaut a lot of errors, so this option is out.
ps: you coud just modify your post and click "Ignore HTML tags in this message (good for code snippets)"
|
|
|
|
|
Is this a console app or a GUI app? In a console app, you could just return from main, while in a GUI app, you could just close the main Form.
|
|
|
|
|
Also look at System::Environment::Exit
|
|
|
|
|
Thanks That worked. If yu must to know my app is GUI based and my class is outside of any Form.
|
|
|
|
|
Saksida Bojan wrote: Thanks That worked. If yu must to know my app is GUI based and my class is outside of any Form.
For Windows Forms apps, Application::Exit would be a better option.
|
|
|
|
|
That one was without any effect.
|
|
|
|
|
hey folks,
I'm trying to build my project and I get the following error message:
Error 4 error C3149: 'System::String' : cannot use this type here without a top-level '^' c:\documents and settings\john\my documents\visual studio 2005\projects\rtdispatch\rtdispatch\DBConnection.h 11
Here is the entire file:
<br />
#include "StdAfx.h"<br />
#include "DBConnection.h"<br />
<br />
using namespace System;<br />
<br />
DBConnection::DBConnection(void){}<br />
<br />
static void DBConnectToDataSource(String connectString){}
static void DBDisconnectFromDataSource(void){}<br />
Whenever I attempt to use a String, I get this error message.
Do I need to instantiate an a String object or something. If so this is not what I'm looking for. I'm trying to simpl declare and define a C style char *
Any info would be great.
Thanks,
John
|
|
|
|
|
System::String does not support stack semantics, so you need to use a String^ instead of a String.
|
|
|
|