|
Hi all,
I am passing string from C++ to C# but not sure which way is more correct. Here it is:
First approach:
CDAnetCSharpHooks::PassString( )
{
char str[] = "String to pass";
DotNetObject *obj = new DotNetObject();
obj->UseStringInDotNet( str );
}
Second approach:
CDAnetCSharpHooks::PassString( )
{
char str[] = "String to pass";
CString temp(str);
System::String * dotNetStr = new System::String( temp);
DotNetObject *obj = new DotNetObject();
obj->UseStringInDotNet( dotNetStr );
}
C# method
public void UseStringInDotNet( String str )
{
// create new thread and use string in it
}
UseStringInDotNet() is creating new thread and that is why PassString() will finish its work before UseStringInDotNet() finishes its own.
Basically first approach is working, but sometimes on the .NET side I have some unpredictable behaviour in memory. I am wondering if that memory for str buffer is cleared before C# get its work done. In this respect will be the second approach more safe ?
Thank you very much in advance for any suggestions
Roman
|
|
|
|
|
Roman Muntyanu wrote: I am wondering if that memory for str buffer is cleared before C# get its work done. In this respect will be the second approach more safe ?
If you look at the IL code, you will see that it is in fact the same, the compiler auto converts char* -> String*. I assume a copy of the buffer will be created, not sure though.
|
|
|
|
|
Hi!
I'm writing program, which send signals on output of LPT port and I'd like to compile driver inpout32.dll into .exe file, because I'd like to have just one file. Can somebody please tell me, how can I compile .dll file into .exe file?
P.S.: Please excuse any mistakes, because english is not my first language
Life is more
|
|
|
|
|
|
Ok,I have a generic Treeview component that I have inherited and it has the following error. When I try to click on the X on the control bar I get the following error:
External component has thrown an exception. Here is the stack trace..
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)....
I have traced this error to the SendMessage fuction i.e the following line
[DllImport("user32.dll")]
private static extern int SendMessage (IntPtr hWnd, int wMsg, IntPtr wParam,int lParam);
If I comment this out in the code and all calls to this function it works fine. Any ideas on the correct fix for this.
As always all help is appreciated.
Sameer
|
|
|
|
|
Try using this version of the function:
<br />
[DllImport("user32.dll")]<br />
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);<br />
|
|
|
|
|
how to upload images into sql server and getting the same image from the database to dispaly it?
sowjanyakumar
|
|
|
|
|
Use the field type image. You can write an image directly to the database and then read it again.
Greetings,
Ingo
------------------------------
A bug in a Microsoft Product? No! It's not a bug it's an undocumented feature!
|
|
|
|
|
I am trying to create a software in C# that has the capability of performing Symbolic Integration & Symbolic Differentiation. Can anybody help me with a few algorithms or source code.
Thanks
Naveed
|
|
|
|
|
For finding an Integral there exists the Risch algorithm. You should use Google to find it. More about symbolic Differentation can be found at MIT-Press Homepage (e.g. http://mitpress.mit.edu/sicp/full-text/sicp/book/node39.html[^]).
Normally other languages are better for such implementations (lisp for example). You can even use standard software if you like (such as maple or mupad)
Greetings,
Ingo
------------------------------
A bug in a Microsoft Product? No! It's not a bug it's an undocumented feature!
|
|
|
|
|
hey i am havin some probs triny to change the contents of a dropDown list that is part of a user control on an asp.net page, when the user changes the dat in the date control i need to check what shud be displayed in the dropDown list for that date and change its contents anyone have any ideas how to go about doin this a an overview wud be very helpful. thanks in advance
|
|
|
|
|
Hey Howzit,
I would like to know how to use the System.Xml.Serialize method to serialize a Textbox or Button into an Xml document.
Can anyone help?
|
|
|
|
|
Hi.
I am trying to leave all the other attributes of a file alone but unset read only.
I am trying
File.SetAttributes(strFileToStreamPath, File.GetAttributes(strFileToStreamPath) ^ FileAttributes.ReadOnly);
which works fine if the file is read only but not if it isn't (it makes it read only!)
How do I do a "OR NOT" sort of thing. I can't see any examples of this in the documentation?
Cheers,
Martin
|
|
|
|
|
Have you tried &~ ?
The the bitwise "AND NOT" operator.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank You!
I've just tried it and that works great!
|
|
|
|
|
How can I find the user's home directory, eg C:\Documents and Settings\Tony? Is there a system constant I can use?
Thanks,
Tony.
|
|
|
|
|
Environment.GetFolderPath(SpecialFolder.ApplicationData)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi Greeg, that gets 'C:\Documents and Settings\Tony\Application Data' whereas I was looking for the parent of that directory. Is there no Xxxx.HomeDirectory?
Thanks,
Tony.
|
|
|
|
|
I'm not completely sure which parameter is correct, all of them are mentioned here, just try them out
If there is no such parameter, you could strip the path like this:
string path = Environment.GetFolderPath(SpecialFolder.ApplicationData);<br />
string newpath = path.Substring(0, path.LastIndexOf(@"\"));
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks again, Greeg. I'll use your code but have also informed the creator of the file that he might be putting it in the wrong place.
Cheers,
Tony.
|
|
|
|
|
Have you tried Personal? Based on the descriptions that's the only likely sounding member of the enum.
|
|
|
|
|
Yes, that one gives 'My Documents'. I got Greeg's solution to work. I think MS don't want us to find the 'home' directory - unfortunately Java apps seem to use it by default!
Cheers,
Tony.
|
|
|
|
|
TonyLinde wrote: Yes, that one gives 'My Documents'. I got Greeg's solution to work. I think MS don't want us to find the 'home' directory - unfortunately Java apps seem to use it by default!
Probably not. As long as the user doesn't do anything cute with thier folder config (my documents can be set to a location other than the default) you should be OK. A more mundane sub folder like in Greegs solution's probably the safest bet.
|
|
|
|
|
<<set to="" a="" location="" other="" than="" the="" default="">>
Which is exactly what I've done in my dev environment. I'm working in a VM where I've set 'My Documents' to the one in the host machine
T.
|
|
|
|
|
string homePath = Environment.GetEnvironmentVariable("USERPROFILE");
|
|
|
|