I am trying to convert a C# .NET wrapper for Microsoft's unmanaged
'cabinet.dll' to Visual Basic .NET and have hit a stumbling block. Here is
the C# code that I am trying to convert:
[DllImport("cabi net.dll",
CallingConventi on=CallingConve ntion.Cdecl,
EntryPoint="FDI Create")]
private static extern IntPtr FdiCreate(
FdiMemAllocDele gate fnMemAlloc,
FdiMemFreeDeleg ate fnMemFree,
FdiFileOpenDele gate fnFileOpen,
FdiFileReadDele gate fnFileRead,
FdiFileWriteDel egate fnFileWrite,
FdiFileCloseDel egate fnFileClose,
FdiFileSeekDele gate fnFileSeek,
int cpuType, // ignored by 32-bit FDI
[In, Out][MarshalAs(Unman agedType.LPStru ct)] CabError erf);
As you can see, this method is defined but without any '{}' brackets. It
also uses the C# 'extern' keyword. A method of the same name is then
declared publicly as follows:
public static IntPtr FdiCreate(
FdiMemAllocDele gate fnMemAlloc,
FdiMemFreeDeleg ate fnMemFree,
FdiFileOpenDele gate fnFileOpen,
FdiFileReadDele gate fnFileRead,
FdiFileWriteDel egate fnFileWrite,
FdiFileCloseDel egate fnFileClose,
FdiFileSeekDele gate fnFileSeek,
CabError erf)
{
return FdiCreate(fnMem Alloc, fnMemFree, fnFileOpen, fnFileRead,
fnFileWrite,
fnFileClose, fnFileSeek, cpuTypeUnknown, erf);
}
My attempt at the converting the first code snippet to VB.NET looks like
this:
<DllImport("cab inet.dll", CallingConventi on:=CallingConv ention.Cdecl, _
EntryPoint:="FD ICreate")> _
Private Shared Function FDICreate(ByVal pfnAlloc As FdiMemAllocDele gate, _
ByVal pfnFree As FdiMemFreeDeleg ate, _
ByVal pfnOpen As FdiFileOpenDele gate, _
ByVal pfnRead As FdiFileReadDele gate, _
ByVal pfnWrite As FdiFileWriteDel egate, _
ByVal pfnClose As FdiFileCloseDel egate, _
ByVal pfnSeek As FdiFileSeekDele gate, _
ByVal cpuType As Integer, <MarshalAs(Unma nagedType.LPStr uct)> _
ByRef perf As CabError) As IntPtr
End Function
Basically, I'm a little lost on the translation. Visual Studio seems to be
allowing me to create another 'Public' funciton named FDICreate, just like
in the C# version, but if there is a problem in my initial attempt at
conversion, I'd like a heads-up now.
Thanks in advance for any help.
Carl
'cabinet.dll' to Visual Basic .NET and have hit a stumbling block. Here is
the C# code that I am trying to convert:
[DllImport("cabi net.dll",
CallingConventi on=CallingConve ntion.Cdecl,
EntryPoint="FDI Create")]
private static extern IntPtr FdiCreate(
FdiMemAllocDele gate fnMemAlloc,
FdiMemFreeDeleg ate fnMemFree,
FdiFileOpenDele gate fnFileOpen,
FdiFileReadDele gate fnFileRead,
FdiFileWriteDel egate fnFileWrite,
FdiFileCloseDel egate fnFileClose,
FdiFileSeekDele gate fnFileSeek,
int cpuType, // ignored by 32-bit FDI
[In, Out][MarshalAs(Unman agedType.LPStru ct)] CabError erf);
As you can see, this method is defined but without any '{}' brackets. It
also uses the C# 'extern' keyword. A method of the same name is then
declared publicly as follows:
public static IntPtr FdiCreate(
FdiMemAllocDele gate fnMemAlloc,
FdiMemFreeDeleg ate fnMemFree,
FdiFileOpenDele gate fnFileOpen,
FdiFileReadDele gate fnFileRead,
FdiFileWriteDel egate fnFileWrite,
FdiFileCloseDel egate fnFileClose,
FdiFileSeekDele gate fnFileSeek,
CabError erf)
{
return FdiCreate(fnMem Alloc, fnMemFree, fnFileOpen, fnFileRead,
fnFileWrite,
fnFileClose, fnFileSeek, cpuTypeUnknown, erf);
}
My attempt at the converting the first code snippet to VB.NET looks like
this:
<DllImport("cab inet.dll", CallingConventi on:=CallingConv ention.Cdecl, _
EntryPoint:="FD ICreate")> _
Private Shared Function FDICreate(ByVal pfnAlloc As FdiMemAllocDele gate, _
ByVal pfnFree As FdiMemFreeDeleg ate, _
ByVal pfnOpen As FdiFileOpenDele gate, _
ByVal pfnRead As FdiFileReadDele gate, _
ByVal pfnWrite As FdiFileWriteDel egate, _
ByVal pfnClose As FdiFileCloseDel egate, _
ByVal pfnSeek As FdiFileSeekDele gate, _
ByVal cpuType As Integer, <MarshalAs(Unma nagedType.LPStr uct)> _
ByRef perf As CabError) As IntPtr
End Function
Basically, I'm a little lost on the translation. Visual Studio seems to be
allowing me to create another 'Public' funciton named FDICreate, just like
in the C# version, but if there is a problem in my initial attempt at
conversion, I'd like a heads-up now.
Thanks in advance for any help.
Carl
Comment