Link Struct / Class From MASM to C/C++???

From: Bryan Parkoff (bryan.nospam.parkoff_at_nospam.com)
Date: 05/31/04


Date: Mon, 31 May 2004 00:22:09 +0000 (UTC)


    I place struct in C/C++ source code while I tell MASM to use EXTRN
keyword to link struct from MASM source code to C/C++ source code. The
problem is that struct members can't be used in MASM. "RECORD" is the only
struct name to access three variables: A1, A2, and A3 in C/C++ source code,
but it is not allowed in MASM. It has only one option to substitute from A1
to memory address + 0H, from A2 to memory address + 04H, and from A3 to
memory address +08H. It works fine, but the problem is that I insert or
remove struct members before I must change 04H, 08H, etc to each struct
member in MASM. It is not very flexible.
    It would be easier to place variables in global variable rather than
struct member. How do I group global variables together in the global scope
such as ALIGN and CACHE in C/C++ source code while functions in MASM access
C/C++ source code's global variables.
    Look at my example code below.

    Please advise.

Here is C/C++ source code below.

#ifdef __cplusplus
extern "C"
{
#endif

struct _RECORD
{
 U_DWORD A1;
 U_DWORD A2;
 U_DWORD A3;
};

_RECORD RECORD;

#ifdef __cplusplus
}
#endif

Here is MASM source code below.

.386
.MODEL flat, C
.DATA

 EXTRN RECORD:PTR

.CODE

MPU__Run PROC NEAR
 XOR EAX, EAX
 MOV EAX, [RECORD+00H]
 MOV EAX, [RECORD+04H]
 MOV EAX, [RECORD+08H]
 RET
MPU__Run ENDP

-- 
Bryan Parkoff


Relevant Pages

  • Re: The Win32ASM Project
    ... Source code doesn't have restrictions, except for what the author puts ... If you sign a contract which puts restrictions ... different version of MASM that doesn't have the so-called restrictions ... they've purchased Microsoft software and they've developed a Windows ...
    (alt.lang.asm)
  • Re: legal Q about masm
    ... > source code available to their customers for some reason? ... on open source, open source doesn't imply that the software is free for any ... in the file and release the new source code under GPL -- perfectly legal ... they're largely developing Win32 apps with MASM. ...
    (alt.lang.asm)
  • Re: A response to Ed Beroset
    ... >> needed to build MASM code and as commercial software owned by ... NO licence allows for it to be made part of a GPL project. ... Source code is another ...
    (alt.lang.asm)
  • Re: The Anti-GPL fun
    ... you can SELL and don't have to reveal you source code to anyone. ... Your headers are not MicroSoft property, and one another day, ... about "MASM32" and reverse, like in the sentence: ... "When i wrote MASM". ...
    (alt.lang.asm)
  • Re: Hiding Sensitive Code
    ... Putting the object code back into C/C++ source code is probably unlikely, ... but not decompiling it into an editable source code of some type, ... > native machine code there is almost no way of decompiling it. ...
    (microsoft.public.fox.programmer.exchange)