Click here to Skip to main content
15,920,956 members
Home / Discussions / C#
   

C#

 
GeneralRe: write xml root element attribute string in .net(C#) Pin
Christian Graus20-Apr-08 23:31
protectorChristian Graus20-Apr-08 23:31 
GeneralProblem in Creating Widget Pin
rakesh_csit20-Apr-08 23:06
rakesh_csit20-Apr-08 23:06 
GeneralRe: Problem in Creating Widget Pin
Christian Graus20-Apr-08 23:31
protectorChristian Graus20-Apr-08 23:31 
GeneralSelectively show custom controls on the toolbox bar in VS2005 Pin
Rey999920-Apr-08 22:55
Rey999920-Apr-08 22:55 
AnswerRe: Selectively show custom controls on the toolbox bar in VS2005 Pin
Rey999920-Apr-08 23:37
Rey999920-Apr-08 23:37 
Generalbase64Binary Pin
JustRonald20-Apr-08 22:46
JustRonald20-Apr-08 22:46 
GeneralRe: base64Binary Pin
Mustafa Ismail Mustafa21-Apr-08 0:09
Mustafa Ismail Mustafa21-Apr-08 0:09 
GeneralRe: base64Binary Pin
JustRonald21-Apr-08 1:43
JustRonald21-Apr-08 1:43 
QuestionHow to get the Runnning instance of Netscape navigator [modified] Pin
renilraj20-Apr-08 21:44
renilraj20-Apr-08 21:44 
GeneralRe: How to get the Runnning instance of Netscape navigator Pin
leppie21-Apr-08 4:18
leppie21-Apr-08 4:18 
Generalproblem run exe file Pin
chf120-Apr-08 21:38
chf120-Apr-08 21:38 
GeneralRe: problem run exe file Pin
Steve Echols20-Apr-08 21:52
Steve Echols20-Apr-08 21:52 
GeneralON exporting a structure inside a dll Pin
Member 475670920-Apr-08 21:18
Member 475670920-Apr-08 21:18 
GeneralRe: ON exporting a structure inside a dll Pin
Christian Graus20-Apr-08 22:08
protectorChristian Graus20-Apr-08 22:08 
GeneralInvalid postback or callback argument Pin
dabuskol20-Apr-08 21:04
dabuskol20-Apr-08 21:04 
GeneralRe: Invalid postback or callback argument Pin
Christian Graus20-Apr-08 22:12
protectorChristian Graus20-Apr-08 22:12 
Questionhow to skip a word document using c#.net Pin
Nitin Raj20-Apr-08 21:02
Nitin Raj20-Apr-08 21:02 
AnswerRe: how to skip a word document using c#.net Pin
Steve Echols20-Apr-08 21:55
Steve Echols20-Apr-08 21:55 
Generalkeyboard hook Pin
Razvan Dimescu20-Apr-08 20:58
Razvan Dimescu20-Apr-08 20:58 
GeneralRe: keyboard hook Pin
leppie21-Apr-08 4:17
leppie21-Apr-08 4:17 
GeneralRe: keyboard hook Pin
Razvan Dimescu21-Apr-08 4:26
Razvan Dimescu21-Apr-08 4:26 
Generalaccess an application existing on a server Pin
michael_jhons20-Apr-08 20:46
michael_jhons20-Apr-08 20:46 
GeneralRe: access an application existing on a server Pin
Christian Graus20-Apr-08 22:09
protectorChristian Graus20-Apr-08 22:09 
GeneralRe: access an application existing on a server Pin
michael_jhons21-Apr-08 20:43
michael_jhons21-Apr-08 20:43 
GeneralMarshaling structure. Exception rises. Pin
bitwise20-Apr-08 20:38
bitwise20-Apr-08 20:38 
Hello!

I'm working on C# wrapper for C library. And I got two structures:
<br />
struct params<br />
{<br />
    char*   info;<br />
    params* next;<br />
};<br />
<br />
struct device<br />
{<br />
    unsigned int flags;<br />
    char*        name;<br />
    char*        description;<br />
    params*      p_params;<br />
    device*      next;<br />
};<br />


And got 2 functions I use:
<br />
int get_device_list( device* dev );<br />
void free_device_list( device* dev );<br />


So, what I do:
<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public class device<br />
{<br />
   [MarshalAs(UnmanagedType(UnmanagedType.U4)<br />
   uint flags;<br />
<br />
   [MarshalAs(UnmanagedType(UnmanagedType.LPStr)<br />
   string name;<br />
<br />
   [MarshalAs(UnmanagedType(UnmanagedType.LPStr)<br />
   string description;<br />
<br />
   IntPtr p_params;<br />
   IntPtr next;<br />
<br />
   public device() <br />
   {<br />
      name        = new string( '\0', 100 );<br />
      description = new string( '\0', 100 );<br />
      flsgs       = 0;<br />
      p_params    = IntPtr.Zero;<br />
      next        = IntPtr.Zero;<br />
   }<br />
<br />
}<br />
<br />
// ??????????? ?-??? ?? DLL<br />
   [Dllimport("api.dll")]<br />
   static extern int get_device_list( IntPtr device_ptr );<br />
<br />
   [Dllimport("api.dll")]<br />
   static extern int free_device_list( IntPtr device_ptr );<br />
<br />
<br />
public static void main()<br />
{<br />
    device dev;<br />
    IntPtr device_ptr = Marshal.AllocHGlobal( Sizeof( typeof( device ) ) );<br />
    Marshal.StructureToPtr( dev, device_ptr, false ) );<br />
<br />
    int result = get_device_list( device_ptr ); // It's ok here<br />
    <br />
    free_device_list( device_ptr );<br />
    // And here I got an exception: System.AccessViolationException was unhandled<br />
    // Message="Attempted to read or write protected memory.<br />
    // This is often an indication that other memory is corrupt." <br />
<br />
    Marshal.FreeHGlobal( device_ptr );<br />
}<br />
<br />


Actually, I can't realize why the call of the first function is successful, and the call of second one leads to exception throwing?
Help please, thanks in advance.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.