News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Another C calling question

Started by Gil, April 11, 2005, 05:46:38 PM

Previous topic - Next topic

Robert Collins

Quote from: hitchhikr on April 12, 2005, 04:29:52 AM
.....note that if you're using C++ compiler (like VC) you'll need to use this instead:


extern "C" unsigned int __stdcall TestProc(unsigned int dwValue);


to tell the compiler that TestProc is the real name of the function and to avoid the name mangling stuff (a c++ compiler would wait for a function called: TestProc@@YGII@Z).


I used 'C' instead of 'C++' so that syntax must be for 'C++' only because if I try that in 'C' I get an unresolved external reference so in plain 'C' I have to omit the "C" part and use just

extern unsigned int _stdcall TestProc(unsigned int dwValue);


Also, you don't need the double underscore, one underscore works fine.







hitchhikr

C++ compilers can use both for backwards compatibility purposes, they usually switch to C mode whenever they're compiling a .c file and C++ mode with .cpp files.

_stdcall is just a convenient macro, the real one is __stdcall (just disable the language extensions in VC and try to compile a _stdcall function in a .c or .cpp file).

Robert Collins

Out of curiosity, can Visual Basic also call a function from assembly? I know it can if the assembly code is a DLL but I mean in the same sense as the above C code called the assembly function.

hitchhikr

VB uses stdcall, theorically it can since it uses ms link to create executables.

I never tried but if i had a guess i'd say that it would probably require some hacks like the modification of the vb executable that launches the linker in order to inject the .obj files into it's command line (most probably by launching a wrapper tool instead of link.exe).

I don't know about vb.net.

Robert Collins

Ummm......I have an example of a Visual Basic program that calls a Java Class function so maybe somewhere along that same line one can use that approach to also call a MASM function or even a C function for all that matters.

pbrennick

Hi Robert,
That seems to be the case.  Since Java compiles to byte code it is very similar to an asm object.  I stopped using Visual Basic a while ago, version 3 was the last that I used.  Version 3 did not create a standard 32 bit executable (PE) even though it created a windows program, so I must assume that it does so now.  Bieb would probably be the one to ask about that one...

Paul