News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Recent posts

#11
The Workshop / Re: Problems attempting to mak...
Last post by sinsi - Today at 02:23:39 PM
Can you do me a favour? Revert to the original configuration options and try that declaration?
I'm curious to see if that fixed it.

It seems to me that forcing an entire C program to use stdcall is...excessive :badgrin:
#12
The Workshop / Re: Problems attempting to mak...
Last post by Jason - Today at 01:53:30 PM
Thanks Sinsi, I was just replying as your post popped up.


I got it going, but geez, I had to jump through some hoops with Visual Studio.

I had to do the following,

Configuration properties > Calling Convention > __stdcall (/Gz)
Configuration properties > Linker > Advanced > Image Has Safe Exception Handlers - No (/SAFESEH:NO)

Don't know if what I have done there is a bad thing or what?  :badgrin:


I guess if anything else, it gives me a playing field when I can test out what I'm trying to do. Can work out the finer details later on. Haha!

Many thanks for your assistance, Sinsi   :thumbsup:
#13
The Workshop / Re: Problems attempting to mak...
Last post by sinsi - Today at 01:50:44 PM
I know SFA about C/C++ but found this
extern "C" int __stdcall addnums(int x,int y)This also assumes you are building a 32-bit app.

That's about as far as I can go since the library seems correct :thumbsup:
#14
The Workshop / Re: Problems attempting to mak...
Last post by Jason - Today at 01:32:24 PM
Dumpbin.exe seems to show that the exported lib has the function in there happily.

    2 public symbols

        1 _addnums@8
        1 _start
#15
The Workshop / Re: Problems attempting to mak...
Last post by Jason - Today at 01:09:04 PM
Ah, right you are! I mistakenly took DWORD as being a double, where it should be an int and have corrected that part of the code.

extern "C" int addnums(int a, int b);

int main()
{
    std::cout << addnums(2,3);
    system("PAUSE");
}


Still unfortunately having grief with the linker though.

Error LNK2001 unresolved external symbol _addnums
It's still insisting that it cant find _addnums (with an underscore).  :undecided:
#16
The Workshop / Re: Problems attempting to mak...
Last post by sinsi - Today at 12:54:59 PM
These two conflict
.model flat, stdcall

extern "C" double addnums(double a, double b)
The ASM code expects integers but the C code is for doubles...

No idea about C/C++ but if you get the calling convention right I assume that the linker would decorate the export name properly.
#17
The Workshop / Re: Problems attempting to mak...
Last post by Jason - Today at 12:25:22 PM
Scratch the above post, I've now got the error down to being unable to find the function

Error LNK2001 unresolved external symbol _addnums
Happening whether I do this "extern "C" double addnums(double a, double b)" or "extern "C" double _addnums(double a, double b)"


This is my main project as it stands now. The asm code is still the same as in the initial post.

#include <iostream>

#pragma comment(lib, "R:/Programming Archive/Source/asm/bin/addnums.lib")

extern "C" double addnums(double a, double b);
//double _addnums(double a, double b);

int main()
{
    std::cout << addnums(2,3);
    system("PAUSE");
}
#18
The Workshop / Re: Problems attempting to mak...
Last post by Jason - Today at 12:19:20 PM
Hi Sinsi, thanks for the reply.

I was just about to post, I got it 'recognised' by VS by using Polib and no longer get that error. However, I am now getting other errors.

Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol _addnums
Error LNK1120 4 unresolved externals
Error LNK2001 unresolved external symbol __imp__system
Error LNK2001 unresolved external symbol ___CxxFrameHandler3
Error LNK2001 unresolved external symbol ___std_terminate

I suspect that the first one is due to the naming decorations that you just mentioned. How does one go about 'decorating' the names?

Many thanks, once again.
#19
The Workshop / Re: Problems attempting to mak...
Last post by sinsi - Today at 12:04:45 PM
I thought you would use LIB, not LINK?
VS might expect the procedure name to be "decorated" too.
#20
The Workshop / Problems attempting to make a ...
Last post by Jason - Today at 11:55:44 AM
Hi Guys,

Very rusty here with ASM, so please bear with me.  :biggrin:

I'm encountering a problem attempting to make a static lib file and getting it to work in a MS Visual Studio C/C++ project.

Just doing a simple function at this stage to add two numbers.

.486
.model flat, stdcall
.code

start:

addnums proc num1:dword, num2:dword
    mov eax, num1
    mov ecx, num2
    add eax, ecx
    ret
addnums endp

end start

It seems to compile and link happily if I do the following and generates an 'addnums.lib' file.

ml.exe /c /coff addnums.asm
link /NOLOGO /SUBSYSTEM:CONSOLE /out:addnums.lib addnums.obj

But if I attempt to use the generated lib file in my C/C++ project it says "Warning LNK4003 - invalid library format; library ignored"

Any ideas on what I might be missing here would be greatly appreciated.  :thumbsup: