Re: Need help to marshall Win32 DLL call to VB.net
- From: "Bart Mermuys" <bmermuys.nospam@xxxxxxxxxxx>
- Date: Sat, 25 Nov 2006 00:21:56 GMT
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
.
- References:
- Need help to marshall Win32 DLL call to VB.net
- From: Gilles Vollant \(MVP\)
- Need help to marshall Win32 DLL call to VB.net
- Prev by Date: Re: explanations
- Next by Date: Re: Looking for something like UML
- Previous by thread: Re: Need help to marshall Win32 DLL call to VB.net
- Next by thread: Printer Properties
- Index(es):
Relevant Pages
|