|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Need help to marshall Win32 DLL call to VB.netI'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 without success Any help or tips will be a lot welcome ! regards Gilles Vollant I found a (bad) solution
<StructLayout(LayoutKind.Sequential)> _ Public Structure DirInfoArrayStruct <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> Public diItem As DIRINFO() End Structure This solution is not very good : - I must known how many item I'll have when I compile (here I put 32) - when a high number of item, I've stack error Hi,
Show quoteHide quote "Gilles Vollant (MVP)" <i***@winimage.com> wrote in message Can't say i tested something like this recently, but you could try something news:OdjN228DHHA.3576@TK2MSFTNGP03.phx.gbl... > 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 > > 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 Show quoteHide quote > > without success > > > > Any help or tips will be a lot welcome ! > > > > regards > > Gilles Vollant > >
Need Help on String.Format() method
Books for learning VB.NET Serialization Help!!!!!!!!!! Adding buttons to form help Embedded Stored Procedure within App VB 2005 Initialising Toobar upload file to web-browser array and shell Animated GIFs in VB.NET 2005 Need a way for the user to add form buttons?????????????????????? |
|||||||||||||||||||||||