WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
 

Help at carry of class C ++ in ASM, can I use an object oriented approach to assembly language coding or I must convert my code to a procedural form instead?

Alex BP
Quote Post


New Member
*

Group: Members
Posts: 5
Member No.: 40
Joined: 29-May 04


Prompt please as on ASM the following code will look:

CODE
int controlsInit = FALSE;

BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved)
{

hInstance = hinstDLL;

if (! controlsInit) {

controlsInit = TRUE;

InitCustomControls(hInstance);

InitCommonControls();

}

return(TRUE);

}


__declspec(dllexport) ClassDesc *LibClassDesc(int i) {

switch(i) {

case 0: return &MeltCD;

default: return 0;

}

}


class MeltClassDesc : public ClassDesc {

public:

int IsPublic() { return TRUE; }

void * Create(BOOL loading=FALSE) { return new MeltMod(); }

const TCHAR * ClassName() { return _T("Melt"); }

SClass_ID SuperClassID() { return OSM_CLASS_ID; }

Class_ID ClassID() { return Class_ID(0xA1C8E1D1, 0xE7AA2BE5); }

const TCHAR* Category() { return _T(""); }

};

static MeltClassDesc MeltCD;

PMEmail Poster
Top
QvasiModo
Quote Post


Just your regular village idiot
******

Group: Moderators
Posts: 462
Member No.: 7
Joined: 13-May 04


The DllMain part is simple, but the rest is OOP stuff and I'm not familiar with it, sorry sad.gif

CODE
.data
hInstance dd 0
controlsInit dd FALSE

.code
DllMain proc hinstDLL:DWORD, fdwReason:DWORD, lpvReserved:DWORD
mov eax,hinstDLL
mov hInstance,eax
.if !controlsInit
mov controlsInit,TRUE
invoke InitCustomControls,hInstance
invoke InitCommonControls
.endif
mov eax,TRUE
ret


Although I would check that fdwReason equals DLL_PROCESS_ATTACH before oding any of that stuff in the code. Take a look at the description of DllEntryPoint at MSDN (http://msdn.microsoft.com).
PMEmail Poster
Top
andrew_k
Quote Post


Active Member
***

Group: Members
Posts: 41
Member No.: 34
Joined: 25-May 04


Hi Alex,
The following is not object oriented. Instead it converts your code to a procedural form. If you are set on an object oriented approach to assembly language coding check out the object oriented forum at:
http://board.win32asmcommunity.net/index.php

...
MeltClassDesc struct 4
; MeltClassDesc data
MeltClassDesc ends

.data
controlsInit DWORD FALSE

.data?
hinstance DWORD ?
MeltCD MeltClassDesc <?> ; static MeltClassDesc MeltCD

.code
DllEntry proc hInstDLL:HINSTANCE, fdwReason:DWORD, lpvReserved:DWORD
push hinstDLL
pop hInstance
mov eax, controlsInit
or eax, eax
jz EXIT
mov controlsInit, TRUE
push hInstance
call InitCustomControls
call InitCommonControls
EXIT:
mov eax, TRUE
ret
DllEntry endp

LibClassDesc proc i:DWORD
mov eax, i
or eax, eax
jnz EXITLIBCLASS
lea eax, MeltCD
ret
EXITLIBCLASS
mov eax, 0
ret
LibClassDesc endp

IsPublic proc
mov eax, TRUE
ret
IsPublic endp

Create proc loading:DWORD ; no default value...
call Get ProcessHeap
push sizeof MeltMod
push 0
push eax
call HeapAlloc
; Note no constructor for MeltMod object called.
; The C++ compiler inserts this call in your C++ code during compilation
; If you need to initialise this memory you will have to explicitly do so yourself
ret
Create endp

... etc etc

Note you will have to create a def file with something like the following:
LIBRARY MeltMod
EXPORTS LibClassDesc
and include it in your .wap project. This has the same effect as using __declspec(dllexport) in (Microsoft) C++, that is the function will be exported for use by any application loading your .dll.
Hope this is of some use to you,
Cheers,
Andrew
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google