Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
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.
GeneralRe: Marshaling structure. Exception rises. Pin
leppie21-Apr-08 4:29
leppie21-Apr-08 4:29 
GeneralRename Excel sheets after exporting to a new Excel spreadsheet Pin
Walaza20-Apr-08 20:21
Walaza20-Apr-08 20:21 
GeneralRe: Rename Excel sheets after exporting to a new Excel spreadsheet Pin
moon_stick21-Apr-08 1:36
moon_stick21-Apr-08 1:36 
GeneralRe: Rename Excel sheets after exporting to a new Excel spreadsheet [modified] Pin
Walaza21-Apr-08 3:28
Walaza21-Apr-08 3:28 
GeneralReading selected items of one listbox to other list box using javascript Pin
csp20-Apr-08 19:45
csp20-Apr-08 19:45 
GeneralRe: Reading selected items of one listbox to other list box using javascript Pin
Christian Graus20-Apr-08 19:53
protectorChristian Graus20-Apr-08 19:53 
GeneralOn calling a function written in c from a dotnet c# application Pin
Member 475670920-Apr-08 19:28
Member 475670920-Apr-08 19:28 
GeneralRe: On calling a function written in c from a dotnet c# application Pin
Christian Graus20-Apr-08 19:54
protectorChristian Graus20-Apr-08 19:54 
GeneralRe: On calling a function written in c from a dotnet c# application Pin
Member 475670920-Apr-08 20:54
Member 475670920-Apr-08 20:54 
GeneralUser permissions to a DCOM object Pin
random420-Apr-08 19:15
random420-Apr-08 19:15 
GeneralRe: User permissions to a DCOM object Pin
Nouman Bhatti20-Apr-08 19:58
Nouman Bhatti20-Apr-08 19:58 
GeneralRe: User permissions to a DCOM object Pin
random421-Apr-08 18:33
random421-Apr-08 18:33 
GeneralLogin Winform Pin
ferspr20-Apr-08 17:34
ferspr20-Apr-08 17:34 
GeneralRe: Login Winform Pin
I.explore.code20-Apr-08 18:44
I.explore.code20-Apr-08 18:44 
GeneralRe: Login Winform Pin
ferspr20-Apr-08 19:27
ferspr20-Apr-08 19:27 
GeneralRe: Login Winform Pin
Nouman Bhatti20-Apr-08 20:04
Nouman Bhatti20-Apr-08 20:04 
GeneralProblem sending a public key encrypted string over a socket Pin
anth12320-Apr-08 13:04
anth12320-Apr-08 13:04 

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.