Re: Win AP question

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Einar Høst (_ebuffer__at_hotmail.com)
Date: 04/16/04


Date: Fri, 16 Apr 2004 10:17:45 +0200

I have a follow-up question:

What to do when the type of struct depends on some other input parameter?
Specifically, I need to call a Win32 API function called GetTapeParameters.

I written this:

[DllImport("kernel32"), SetLastError=true]
static extern int GetTapeParameters(
  IntPtr hTape,
  int dwOperation,
  ??? lpTapeInformation
)

The problem is that lpTapeInformation should point to different kinds of
structs depending on the value for dwOperation (dwOperation
GET_TAPE_MEDIA_INFORMATION implies a TAPE_GET_MEDIA_PARAMETERS struct,
whereas dwOperation GET_TAPE_DRIVE_INFORMATION implies a
TAPE_GET_DRIVE_PARAMETERS struct). Therefore, I can't simply put ref
<struct-type> lpTapeInformation...

Any help would be much appreciated!

- Einar



Relevant Pages

  • Re: Win AP question
    ... I need to call a Win32 API function called GetTapeParameters. ... > structs depending on the value for dwOperation (dwOperation ... You can declare the function once for each struct type... ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Win AP question
    ... >> static extern int GetTapeParameters( ... > You can declare the function once for each struct type (basically you can ... > Or, you can use unsafe code, and pass the value as you would in C. ... I just discovered that, like you say, you can overload the function. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Referencing an HBITMAP from a struct
    ... also change the paramater which takes the struct to ref ... > private static extern int SendMessage( ... > If you do not need the bitmap parameter then set it to IntPtr.Zero. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: NullReferenceException when passing structures by reference to a C API
    ... I really don't think it has anything to do with the struct itself, ... Object reference not set to an instance ... public static extern int getadminprof(string szLogin, ...
    (microsoft.public.dotnet.framework.interop)
  • Re: How would I convert this struct?
    ... public static extern int z4adrinq; ... > I converted it like you suggested but I receive: " Can not marshal parameter> #1: Invalid managed/unmanaged type combination (this value type must be> paired with Struct)." ... >> public string detail_code; ...
    (microsoft.public.dotnet.languages.csharp)