473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

VB.NET implementation of DllImport from C#?

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("cabinet.dll",
CallingConvention=CallingConvention.Cdecl,
EntryPoint="FDICreate")]
private static extern IntPtr FdiCreate(
FdiMemAllocDelegate fnMemAlloc,
FdiMemFreeDelegate fnMemFree,
FdiFileOpenDelegate fnFileOpen,
FdiFileReadDelegate fnFileRead,
FdiFileWriteDelegate fnFileWrite,
FdiFileCloseDelegate fnFileClose,
FdiFileSeekDelegate fnFileSeek,
int cpuType, // ignored by 32-bit FDI
[In, Out][MarshalAs(UnmanagedType.LPStruct)] 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(
FdiMemAllocDelegate fnMemAlloc,
FdiMemFreeDelegate fnMemFree,
FdiFileOpenDelegate fnFileOpen,
FdiFileReadDelegate fnFileRead,
FdiFileWriteDelegate fnFileWrite,
FdiFileCloseDelegate fnFileClose,
FdiFileSeekDelegate fnFileSeek,
CabError erf)
{
return FdiCreate(fnMemAlloc, fnMemFree, fnFileOpen, fnFileRead,
fnFileWrite,
fnFileClose, fnFileSeek, cpuTypeUnknown, erf);
}

My attempt at the converting the first code snippet to VB.NET looks like
this:

<DllImport("cabinet.dll", CallingConvention:=CallingConvention.Cdecl, _
EntryPoint:="FDICreate")> _
Private Shared Function FDICreate(ByVal pfnAlloc As FdiMemAllocDelegate, _
ByVal pfnFree As FdiMemFreeDelegate, _
ByVal pfnOpen As FdiFileOpenDelegate, _
ByVal pfnRead As FdiFileReadDelegate, _
ByVal pfnWrite As FdiFileWriteDelegate, _
ByVal pfnClose As FdiFileCloseDelegate, _
ByVal pfnSeek As FdiFileSeekDelegate, _
ByVal cpuType As Integer, <MarshalAs(UnmanagedType.LPStruct)> _
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
Nov 21 '05 #1
1 3860
In article <#t**************@tk2msftngp13.phx.gbl>, Vagabond Software wrote:
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("cabinet.dll",
CallingConvention=CallingConvention.Cdecl,
EntryPoint="FDICreate")]
private static extern IntPtr FdiCreate(
FdiMemAllocDelegate fnMemAlloc,
FdiMemFreeDelegate fnMemFree,
FdiFileOpenDelegate fnFileOpen,
FdiFileReadDelegate fnFileRead,
FdiFileWriteDelegate fnFileWrite,
FdiFileCloseDelegate fnFileClose,
FdiFileSeekDelegate fnFileSeek,
int cpuType, // ignored by 32-bit FDI
[In, Out][MarshalAs(UnmanagedType.LPStruct)] 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(
FdiMemAllocDelegate fnMemAlloc,
FdiMemFreeDelegate fnMemFree,
FdiFileOpenDelegate fnFileOpen,
FdiFileReadDelegate fnFileRead,
FdiFileWriteDelegate fnFileWrite,
FdiFileCloseDelegate fnFileClose,
FdiFileSeekDelegate fnFileSeek,
CabError erf)
{
return FdiCreate(fnMemAlloc, fnMemFree, fnFileOpen, fnFileRead,
fnFileWrite,
fnFileClose, fnFileSeek, cpuTypeUnknown, erf);
}

My attempt at the converting the first code snippet to VB.NET looks like
this:

<DllImport("cabinet.dll", CallingConvention:=CallingConvention.Cdecl, _
EntryPoint:="FDICreate")> _
Private Shared Function FDICreate(ByVal pfnAlloc As FdiMemAllocDelegate, _
ByVal pfnFree As FdiMemFreeDelegate, _
ByVal pfnOpen As FdiFileOpenDelegate, _
ByVal pfnRead As FdiFileReadDelegate, _
ByVal pfnWrite As FdiFileWriteDelegate, _
ByVal pfnClose As FdiFileCloseDelegate, _
ByVal pfnSeek As FdiFileSeekDelegate, _
ByVal cpuType As Integer, <MarshalAs(UnmanagedType.LPStruct)> _
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


Quick glance, and with out the definitions of the delegates/structs - it
looks ok. The only real comment I have is that the
MashalAs(UnmanagedType.LPStruct) is probably unnecessary (in both
versions actually).

--
Tom Shelton
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Juerg Staub | last post by:
Hi, I have implemented IInternetProtocol and IInternetProtocolRoot in my protocol handler. Whenever I try to register the instance with IInternetSession::RegisterNameSpace, I receive a...
15
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
4
by: Dave Bailey | last post by:
I have an application installed on a web server. When forst intalled it worked fine. The administrator rebooted the server and then when accessing the app the folowing error appears: CryptoAPI...
9
by: Ole Christensen | last post by:
I'm trying to make a sort of conditional compilation in my C# code because my app is intended to run on both a Pocket PC and on a normal desktop PC. My code uses a call to an API function that on...
3
by: Mark Jerde | last post by:
I'm sill learning VS .NET 2003, not an expert yet. I'm calling an unmanaged C++ DLL from C# using . When the whole project is done I will be calling a total of 5 C++ DLLs from C#. All the DLLs...
1
by: Brian Anderson | last post by:
Hello, I have a native, C++ console app that uses ~26MB of RAM when it runs. It uses quite a lot of RAM to make some math but will never xceed 26MB. Now I've made a dll out of this code and...
2
by: Brian Anderson | last post by:
Hello, is it possible to use DllImport to call a DLL in ASP.NET ? Or is it necessarry that my DLL has to be copied into \System32 ? My DLL is a native C++ 7.1 DLL (not managed, no COM, no...
2
by: Ed | last post by:
Hello, dear all, I often see these two import usage in the code. Both are the interface to use the Dll library. I think they are the same. Normally P/Invoke means using the to import the dll....
1
by: elke | last post by:
Hi, I want to use an unmanaged dll in C# .net and I'm having some troubles witch a function that should return an array. I'm new at this, so I don't know what I'm doing wrong. Here is some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.