|
Why two Posts?
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
unlike C/++ you can't just cast const away anytime you find it annoying.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
How do I change the datagrid.readonly property at run time.
Please help me in this regard.
|
|
|
|
|
look the meaning of "readonly" in the dictionary.
Yusuf
|
|
|
|
|
Hi Guys,
Im stuck in a weird problem, and hope the experts here can help me.
I have a C# VS2005 project. I call a Borland C DLL in it, using:
System.Runtime.InteropServices.DllImport(......
to get a function 'GetSearchResults' from the DLL like this:
int Result = Module1.GetSearchResults (handle, ref DeviceInfo, 1);
Module1: an internal sealed class where the DLLImport is done and device_info_t is declared.
DeviceInfo: is a object of a structure called device_info_t . I am supposed to get the Search-Result back in this structure.
The C function looks like this:
int GetSearchResults(const handle_t handle, device_info_t results[], const size_t count);
Now, when I run this code, I get a 'System.AccessViolationException', saying 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt'.
Does anyone have an idea, whats happening, whats causing this error?
Thank you soo much guys...
|
|
|
|
|
indogerman wrote: Does anyone have an idea, whats happening, whats causing this error?
Assuming the Borland C DLL works properly and is NOT the source of the error then probably the Interop (PInvoke) has not been developed correctly. However since you did not post any of it we have no way of knowing.
led mike
|
|
|
|
|
How do you declare the device_info_t struct into the c# project? Do you use the StructLayout attribute? Are there const size arrays into struct?
|
|
|
|
|
My guess is that even though you have only one DeviceInfo, you need to make an array to pass to the function since that is what it expects.
|
|
|
|
|
Hi All,
Thanks for your suggestions!
@Gideon: I tried as you suggested, making an array. Now weirdly, the program ends abruptly at the point of function-call (where the Exception was occurring earlier.)
@oobimoo: Well, I didnt know that one cant declare a struct in C#...For me, I didnt get an error yet. This is what i am doing:
public struct device_info_t
{
public int size;
.......
}
@led mike:
I am not so sure how the PInvoke is done. This is how its done in my project. Is there any better way?
[System.Runtime.InteropServices.DllImport("device", EntryPoint="GetSearchResults", ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
public static extern int GetSearchResults(int handle, ref device_info_t results, int _count);
Any suggestion guys?
Whats still very weird, why is this AccessViolationException occurring?
Thanks a lot!
|
|
|
|
|
You can declare a structure in C#, but if you are going to use it for PInvoke, you need to use an attribute to make sure it gets laid out correctly. It should be:
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public struct device_info_t
{
public int size;
....
}
Then make sure you declare the fields in the structure in the same order as in the header file.
Also, I would try changing the signature of the function definition. Even if the size_t structure fits in an integer, I would go ahead and define it anyway to be safe.
Original:
int GetSearchResults(const handle_t handle, device_info_t results[], const size_t count);
C#
int GetSearchResults(IntPtr handle, device_info_t results[], size_t count);
|
|
|
|
|
Hi all,
I use C# and SQL Server,I make DataSet by QueriesTableAdapter but I don't know how can use DataSet in C# program when i use Wizard DataSet
|
|
|
|
|
What exactly do you wanna do?
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I make DataSet By Wizard but when I want to use this DataSet in my application,C# does not know DataSet and not show method and properties
|
|
|
|
|
mghiassi wrote: C# does not know DataSet and not show method and properties
So you should go back to your beginners books and tutorials until you understand how to add new files and classes to a project before you start messing around with DataSets.
led mike
|
|
|
|
|
Perhaps you should first ask yourself "why" to use a DataSet in your application.
|
|
|
|
|
|
It depends on the application that have created your dat file.
Is-it your own application ? did you use serialization ?
...
|
|
|
|
|
Hi all I need to get the source ip from a udp header I read udp data in the following way.
byte[] data = null;
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, port);
Socket newsock = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ipep);
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint tmpRemote = (EndPoint)(sender);
DateTime file_time = DateTime.Now;
int file_counter = 0;
while(true)
{
int counter = 0;
data = new byte[2048];
Console.WriteLine();
Console.WriteLine("Waiting for a client...");
recv = newsock.ReceiveFrom(data, ref tmpRemote);
Does anybody know how to do this
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
Stephen Lintott wrote: Hi all I need to get the source ip from a udp header I read udp data in the following way.
Stephen Lintott wrote: recv = newsock.ReceiveFrom(data, ref tmpRemote);
I believe the source ip is staring you in the face (if not, hint: look at tmpRemote after the call).
|
|
|
|
|
First I thought that that was it but running the program I get our Gateway address instead of the router address. Why is this?
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
That sounds normal if the packet originated outside the local network. It is the normal behaviour of NAT I believe. If you are doing multicast, it wont even go beyond the local network, that's how UDP multicast work.
|
|
|
|
|
Thanks I was unsure about this.
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
Hi All,
There is 2 comboboxes named "cmbMinNoSem", "cmbMinNoSem" and an Xml (that fetches the values from database). I want to get selected the combobox value that is in the xml. I have written the code as below:
cmbMinNoofSem.SelectedValue = xmlDom.GetElementsByTagName("min_no_of_semesters")[0].InnerText;
cmbMaxNoofSem.SelectedValue = xmlDom.GetElementsByTagName("max_no_of_semesters")[0].InnerText;
The first statement works fine but the second one does'nt
Thanks in advance.
Regards,
chanzeb chaudhary
|
|
|
|
|
Anyone know how you can get the current refresh rate of one (or more) monitors attatched to a computer? I can't seem to find it.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Start with the Win32 API GetDeviceCaps(), look for VREFRESH.
That's how we did it in the old days, anyway. This model may have changed with XP and Vista.
I would start by googling GetDeviceCaps, at any rate.
|
|
|
|