|
What do you mean it's not being marshaled correctly?
As in it won't compile?
As in when you try to use the structure it behaves unexpectedly?
Did you try using the MasrhalAs(UnmanagedType.R4) or MarshalAs(UnmanagedType.R8) properties? As I recall, a C double is smaller than a C# double or something to that effect. (The reason I think this is because for some reason I think that a C long is actually 4 bytes while a C# long is 8 bytes)
So try adding a MarshalAs(UnmanagedType.R4) to your Double. (R4 and R8 marshal floating-point numbers, I2, I4, and I8 marshal integers)
|
|
|
|
|
Can i create a function template in c#.if so how to do it?
Nithya
|
|
|
|
|
Only in VS.NET 2005, which is currently in beta 2.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
In C# code I declared like this:
[DllImport("mydll.dll")]
public static extern int SearchString(out double x);
And I called the function:
double m_vo2Max=1;
SearchString(out m_vo2Max);
The SearchString function is on the mydll.dll. This dll is written in VC++ and the description is here:
#include "stdafx.h"
#include <stdio.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int WINAPI SearchString (double &X)
{
FILE *F;
char szString[255];
F= fopen("C:\\ParaLimit1.tbf", "rt");
fgets(szString, 255, F);
fclose(F);
return 1;
}
I always have an error : System.NullReferenceException
Additional Information : Object reference not set to an instance of an object.
I checked and found out that the error in the code below:
fgets(szString, 255, F);
Can you help me to solve this error.
Thank you,
|
|
|
|
|
Why are you using C file handling instead of C++ ?
You should check if F is NULL, perhaps that's where the real problem is.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have a console application and let's say I have another console application (native c++ and I don't have the source) and I want to run that native application with my app like I would start it in cmd.exe.
For example, say my app was named ant.bat, to run it in the console I would type the C:\antroot\ant and it would run and display it's text in that console window.
Now I want to start ant.bat (Process.Start()???) and but have it run in my console window that my managed app is running in. Because if I just use Process.Start() it runs ant.bat in a new console window and closes when execution is complete.
Any ideas?
/\ |_ E X E GG
|
|
|
|
|
Try this:
public static void launch( string name, string workingDir )
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = name;
process.StartInfo.WorkingDirectory = workingDir;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
System.Console.Write(process.StandardOutput.ReadToEnd());
}
You could also throw in process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; , but I don't think it's necessary.
By the way, this also answers the gcc question below.
Matt Gerrans
|
|
|
|
|
Thanks that works just as I like.
I have another question though. If, for example, I wanted to set an environmental variable with my computer I would go like this in the command prompt....
<br />
set JAVA_HOME=C:\jdk1.3.1_16
How would I do this programmicly in C#?
Thank you for your time.
/\ |_ E X E GG
|
|
|
|
|
|
|
How can I FullRowSelect in DataGrid using C#?
Jassim Rahma
|
|
|
|
|
You can use DataGrid.CurrentRowIndex = index
Hugo Migneron
|
|
|
|
|
Hello,
I am using UDP protocol to broadcast a packet on the network. After I send this packet, some devices on the network answer with a UDP datagram packet containing some information.
My problem is that whenever one of these devices answer, (I know I get the packet because the Socket.Receive function returns me the data I am waiting for) I don't know who this packet is coming from. I am looking for a way to know the IP Address of the packet sender.
This is my code :
<br />
IPEndPoint Broadcast = new IPEndPoint(IP, 2000);<br />
EndPoint BroadcastEP = (EndPoint)Broadcast;<br />
<br />
socket = new Socket(System.Net.Sockets.AddressFamily.InterNetwork,<br />
SocketType.Dgram, ProtocolType.Udp);<br />
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);<br />
socket.SendTo(msg, 0, msg.Length, SocketFlags.None, BroadcastEP);<br />
Then, if I use the socket.Receive function, I get the payload of the packet but not the header information. Is there a way to get this information (Source's IP Address) with System.Net.Sockets or with System.Net.Sockets.UpdClient ?
I thought I could get this information by using socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.PacketInformation, ... but I just can't seem to figure out how to use it correctly.
If anyone knows how to do this, it would be greatly appreciated!
Hugo Migneron
|
|
|
|
|
Hi
When I run g++ (to compile) using process.start I get the error: "g++.exe: Main.cpp: No such file or directory"
If I run g++ using the same arguments from command prompt it runs fine. whats going wrong?
cheers
|
|
|
|
|
|
|
You need to specify the full path of the Main.cpp file when you run it using Process.Start, or, you need to set the current directory to the directory where Main.cpp resides before starting the process.
This is because a process spawned using Process.Start by default, has its current directory set to the application directory of the parent process.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks a lot! How can I "set the current directory to the directory where Main.cpp resides before starting the process"
Cheers again
|
|
|
|
|
You can use the ProcessStartInfo's WorkingDirectory property.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
Oops, sorry Senthil, I didn't see your reply to yourself where you already pointed this out!
Matt Gerrans
|
|
|
|
|
|
i have managed to make designcollection to work but i don't know how to create controls with the collection editor.
I have a Item, ItemCollection, ItemCollectionDesigner
an Item consist of text , int and picture
i want to attach a picturebox to it so that it auto generate on my usercontrol...
|
|
|
|
|
I was wondering if anyone can point me in the right direction to replicate the Internet Explorer-style Menu Bar in C# using Windows Forms?
I can easily create the menu using the toolbar control, but I run into problems trying to size the text correctly without the icon. Either I get too much space on the top (setting the toolbar TextAlign to Underneath), or I get too much space to the left (setting to Right). How do I get rid of the space?
~tekun
|
|
|
|
|
Hi, I have an lisview, when the lisview is filled, if it need draw vertical scroll, but if this happen, the horizontal scroll is drawin too to fit the columns with the vertical scroll width.
I would like to fix this resizing the columns with id the vertical scroll is visble.
How can I detect if vertical scroll is visible?
I have prove to catch the api messages in wnproc but I dont know wich message to detect.
Thank you!
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|