Calling WinAPI Functions from .NET

G

Guest

Are there any concise rules about when you need to marshal data to WinAPI
calls, and when you don't? It appears that most times you can call WinAPI
calls directly from .NET without any preparation. For example

Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal
pPrinterName As String, ByVal phPrinter As Integer,
<MarshalAs(UnmanagedType.Struct)> ByRef pDefault As PRINTER_DEFAULTS) As
Integer

Dim tmpHandle As Int32
Dim msDeviceName as String = "MyPrinter"
OpenPrinter(msDeviceName, tmpHandle, 0)

However, some functions appear to require all kinds of fancy manipulation
before you get to call them--particularly ones which require structures or
arrays. (See http://www.codeproject.com/vb/net/printwatchvbnet.asp). Why
isn't .NET smart enough to handle this "under the covers", the way that VB6
is?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top