Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all

I want to extract a drive information from iSCSI initiator.
C++
HRESULT WINAPI GetIscsiTargetInformation(
  _In_     PTCHAR                   TargetName,
  _In_opt_ PTCHAR                   DiscoveryMechanism,
  _In_     TARGET_INFORMATION_CLASS InfoClass,
  _Inout_  PULONG                   BufferSize,
  _Out_    PVOID                    Buffer
);


I unable to convert above dll call to C#, especially Target Information class.
Any help ?

What I have tried:

I have tried:
[DllImport("iscsidsc.dll")]
internal static extern uint GetIscsiTargetInformation(byte[] TargetName, byte[] DiscoveryMechanism, InfoClass, ref uint BufferSize, ref byte[] Buffer);
Posted
Comments
Sergey Alexandrovich Kryukov 28-Apr-16 23:07pm    
To start with, PTCHAR and TCHAR are not "real" types, but types depending on target platform used to compile C/C++ code, either single-byte char or WCHAR. In all cases, the PTCHAR parameters can be marshaled as System.String.

You cannot use AnyCPU in this case. Alternatively, you can P/Invoke Windows API LoadLibrary and GetProcAddress and load different versions of the library to different CPU, depending in currently running process (x86, x86-64, IE-64, x32 or x32 under WoW64...)

—SA
Khayralla 29-Apr-16 9:22am    
thanks for your comment, my application is x64 bit.
Sergey Alexandrovich Kryukov 29-Apr-16 11:46am    
And (probably I forgot to mention, it is related to the 1st paragraph), it depends on how the managed DLL is compiled, as Unicode or not. Depending on that, you can use MarshalAsAttribute at the parameter, to indicate unmanaged type as PChar or PWideChar. Essentially, this is what PTChar can be conditionally compiled to.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900