Re: Need help to marshall Win32 DLL call to VB.net

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



Hi,

"Gilles Vollant (MVP)" <info@xxxxxxxxxxxx> wrote in message
news:OdjN228DHHA.3576@xxxxxxxxxxxxxxxxxxxxxxx
Hello

I've (in WinImage SDK http://www.winimage.com/wima_sdk.htm ) a function
that I need to use from a VB.Net apps

First, on the unmanaged Win32 DLL, I've a function which get the number of
item (function GetNbEntryCurDir)
after, I allocate an array and I call GetDirInfo to fill the array


// GetNbEntryCurDir : Get the number of entry of cur directory
DWORD WIMAAPI GetNbEntryCurDir(HIMA hIma);


#define MAXLFN 256

typedef struct
{
char nom[8];
char ext[3];
char szCompactName[13];
BYTE bAttr;

BYTE dir_CreateMSec;
WORD dir_CreateDate;
WORD DosTime;
WORD DosDate;

BOOL fIsSubDir;
BOOL fSel; // for private use of client app.
BOOL fLfnEntry;
DWORD dwSize;
UINT uiPosInDir;
DWORD dwLocalisation;
DWORD dwTrueSize;
char longname[MAXLFN];
WORD dir_CreateTime;
WORD dir_LastAccessDate;
} DIRINFO;


// GetDirInfo : Get info about the entry of cur directory
// LPDIRINFO : array of DIRINFO that will receive the info
// (use GetNbEntryCurDir for know the size needed)
// bSort : specify how the file must be sort
// (SORT_NONE, SORT_NAME, SORT_EXT, SORT_SIZE or SORT_DATE)
BOOL WIMAAPI GetDirInfo(HIMA hIma,LPDIRINFO lpdi,BYTE bSort);

on C++ unmanager, I do:
{
HIMA hIma; // filled by other function
DWORD dwNumber = GetNbEntryCurDir(hIma);
DIRINFO* pDirInfo = (DIRINFO*)malloc(sizeof(DIRINFO) * dwNumber );
GetDirInfo(hIma,pDirInfo,0);
DWORD i;
for (i=0;i<dwNumber;i++) printf("%s\n", (pDirInfo+i)->longname)
}

I want do the same work on VB.net

I had converted DIRINFO structure on VB.net

Public Const MAXLFN As Short = 256

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _

Public Structure DIRINFO

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=8)> Public nom As String

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=3)> Public ext As String

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=13)> Public szCompactName
As String

Public bAttr As Byte

Public dir_CreateMSec As Byte

Public dir_CreateDate As Short

Public DosTime As Short

Public DosDate As Short

Public fIsSubDir As Integer

Public fSel As Integer

Public fLfnEntry As Integer

Public dwSize As Integer

Public uiPosInDir As Integer

Public dwLocalisation As Integer

Public dwTrueSize As Integer

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXLFN)> Public longname As
String

Public dir_CreateTime As Short

Public dir_LastAccessDate As Short

End Structure



I need help to convert VB Array to unmanaged C-Style array. I suppose I
need <MarshalAs(UnmanagedType.LPArray)> or
<MarshalAs(UnmanagedType.ByValArray)>



I tried

Declare Function GetDirInfo Lib "wimadll.dll" (ByVal Ima As Integer,
<MarshalAs(UnmanagedType.LPArray)> ByRef dia As DIRINFO, ByVal bSort As
Byte) As Boolean



Can't say i tested something like this recently, but you could try something
like:

Imports System.Runtime.InteropServices

Declare Function GetDirInfo Lib "wimadll.dll" (ByVal Ima As Integer,
<[In](),Out()> ByVal dia() As DIRINFO, ByVal bSort As Byte) As Boolean

HTH,
Greetings



without success



Any help or tips will be a lot welcome !



regards

Gilles Vollant




.



Relevant Pages

  • Need help to marshall Win32 DLL call to VB.net
    ... I allocate an array and I call GetDirInfo to fill the array ... DWORD WIMAAPI GetNbEntryCurDir; ... // LPDIRINFO: array of DIRINFO that will receive the info ... on C++ unmanager, I do: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: IOCTL_POWER_XXX method calls
    ... Paul, I understand how to implement your suggestions if the parameter ... // in the managed array of bytes. ... internal const int DeviceDxOffset = 0; ... BOOL PWM_IOControl (DWORD hOpenContext, DWORD pwCode, PBYTE pBufIn, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Whats the most efficient testing of variables?
    ... >>I need to quickly compare a DWORD with a list of DWORDs to ... >>switch won't work because both are variables. ... >linear search of an array ) will be faster. ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: IOCTL_POWER_XXX method calls
    ... // in the managed array of bytes. ... internal const int DeviceDxOffset = 0; ... // declare the accessor as an array and create and return an embedded ... BOOL PWM_IOControl (DWORD hOpenContext, DWORD pwCode, PBYTE pBufIn, ...
    (microsoft.public.dotnet.framework.compactframework)