Thread: Assembly and C++

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    15

    Assembly and C++

    Hi guys, I have asked this question on other forums and no one seems to know the answer...

    I wrote a dll in assembly to test the functionallity between ASM dll's and C++. I am however lost. After compiling the following ASM code into a DLL :

    Code:
    .386
    .model flat,stdcall
    option casemap:none
    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    
    .data
    
    .code
    
    MyTest Proto :DWORD
    
    
    DllMain proc hInstance:HINSTANCE, reason:DWORD, reserved1:DWORD
        mov  eax,TRUE
        ret
    DllMain Endp
    MyTest proc mynum:DWORD
        inc [mynum]
        ret    
    MyTest endp
    MyTest2 proc
        ret    
    MyTest2 endp
    End DllMain
    I started a new VC++.NET Console project. I went to msdn and read up on loading dll's. So I went ahead and used LoadLibrary and sure enough the dll was loaded. After this success I used GetProcAddress to find "MyTest2", and everytime it returns NULL.

    Is it possible to use ASM dll's in C++? If so, do you know of a resource I could look at or possibly have some source? Any help is appreciated.

    -Sean

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Most likely reason is that the function isn't listed in the export list of the DLL. Loading it into the dependency viewer could confirm that.
    The solution would be a .def file fed to the linker.

    It should also be mentioned that Test1 doesn't honor the __stdcall convention, which is the usual convention in DLLs. Neither does it honor the naming convention for __stdcall. And finally, it simply has no visible effect, because it increments a copy of the number passed. (I think. I'm not very familiar with MASM syntax.)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    15
    ok, I was not aware of that! arg! You are correct, it increments a number passed to it... which is just a test, since I want to get it working before i write a few hundred lines of ASM.

    Ok, is there a msdn or such resource for __stdcall that I could look at and make compatible?

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    http://msdn.microsoft.com/library/de...___stdcall.asp

    You clean the stack by using the ret instruction with an argument, e.g.
    ret 4
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed