Click here to Skip to main content
15,905,229 members
Home / Discussions / C#
   

C#

 
GeneralRe: Managed HTML - GPL Pin
Roger Alsing15-Jun-04 21:25
Roger Alsing15-Jun-04 21:25 
GeneralRe: Running Event Methods Pin
myNameIsRon15-Jun-04 20:20
myNameIsRon15-Jun-04 20:20 
GeneralRe: Running Event Methods Pin
Stefan Troschuetz15-Jun-04 21:39
Stefan Troschuetz15-Jun-04 21:39 
GeneralRe: Running Event Methods Pin
myNameIsRon16-Jun-04 6:27
myNameIsRon16-Jun-04 6:27 
GeneralCompile Time Unmanaged DLL Checking Pin
MKlucher15-Jun-04 19:21
MKlucher15-Jun-04 19:21 
GeneralRe: Compile Time Unmanaged DLL Checking Pin
Heath Stewart16-Jun-04 4:06
protectorHeath Stewart16-Jun-04 4:06 
GeneralRe: Compile Time Unmanaged DLL Checking Pin
MKlucher16-Jun-04 6:40
MKlucher16-Jun-04 6:40 
GeneralRe: Compile Time Unmanaged DLL Checking Pin
Heath Stewart16-Jun-04 8:36
protectorHeath Stewart16-Jun-04 8:36 
But again, why would you P/Invoke a method before seeing if it either exists? That's like putting the cart before the horse. Smile | :)

Data-type checking isn't supported because you're marshaling to an unmanaged platform. C/C++ doesn't perform any type checking, either, except for what the compiler can perform at compile-time. In an unmanaged world, arguments and return values are only pointers on the stack (most usually). There would be no way to determine this using a managed compiler.

The best way to avoid errors is to truly understand the unmanaged and managed types, like that an unmanaged int is platform-dependent, i.e. 32 bits on a 32-bit processor and 64 bits on a 64-bit processor,thus you should use an IntPtr. A LONG is always 32 bits, hence is a managed Int32 (C#'s int primitive). A char* is a managed string (no ref or out) and should use CharSet.Ansi, where an LPTSTR is also a string but should use CharSet.Auto, etc. etc.

One thing to note is that currently in the .NET FCL Microsoft uses int where it should be an IntPtr because .NET 1.x does not support the 64-bit platform (it will in 2.0). I suspect they will either change to using IntPtr internally or maintain two different builds specifying an int for 32-bit platforms and a long for 64-bit platforms. I honestly don't know, but making your code use an IntPtr now will ensure that when it is compiled for the 2.0 framework and run on a 32- or 64-bit platform that it will work correctly.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Compile Time Unmanaged DLL Checking Pin
MKlucher16-Jun-04 10:13
MKlucher16-Jun-04 10:13 
GeneralRe: Compile Time Unmanaged DLL Checking Pin
Heath Stewart16-Jun-04 10:15
protectorHeath Stewart16-Jun-04 10:15 
GeneralCalendar Control Pin
Tarakeshwar Reddy15-Jun-04 19:04
professionalTarakeshwar Reddy15-Jun-04 19:04 
GeneralRe: Calendar Control Pin
Heath Stewart16-Jun-04 4:04
protectorHeath Stewart16-Jun-04 4:04 
GeneralSending messages from a thread Pin
caraboss15-Jun-04 18:18
caraboss15-Jun-04 18:18 
GeneralRe: Sending messages from a thread Pin
Corinna John15-Jun-04 20:04
Corinna John15-Jun-04 20:04 
GeneralRe: Sending messages from a thread Pin
caraboss16-Jun-04 3:45
caraboss16-Jun-04 3:45 
GeneralRe: Sending messages from a thread Pin
Heath Stewart16-Jun-04 4:00
protectorHeath Stewart16-Jun-04 4:00 
GeneralRe: Sending messages from a thread Pin
caraboss16-Jun-04 4:17
caraboss16-Jun-04 4:17 
GeneralRe: Sending messages from a thread Pin
caraboss16-Jun-04 4:40
caraboss16-Jun-04 4:40 
QuestionIndexer for a variables property? Pin
khan200015-Jun-04 17:00
khan200015-Jun-04 17:00 
AnswerRe: Indexer for a variables property? Pin
Heath Stewart16-Jun-04 3:58
protectorHeath Stewart16-Jun-04 3:58 
GeneralRealmForge GDK Game Development kit Pin
Liskl15-Jun-04 16:37
Liskl15-Jun-04 16:37 
GeneralDrag and Drop to Explorer Pin
Anders Molin15-Jun-04 14:17
professionalAnders Molin15-Jun-04 14:17 
GeneralRe: Drag and Drop to Explorer Pin
Heath Stewart16-Jun-04 3:48
protectorHeath Stewart16-Jun-04 3:48 
GeneralRe: Drag and Drop to Explorer Pin
Anders Molin16-Jun-04 3:52
professionalAnders Molin16-Jun-04 3:52 
GeneralDetermining the currently running processes Pin
sam00715-Jun-04 12:54
sam00715-Jun-04 12:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.