flat assembler
Message board for the users of flat assembler.

Index > Windows > Calling and DLL

Author
Thread Post new topic Reply to topic
denial



Joined: 12 Sep 2004
Posts: 98
denial 06 Jan 2005, 16:40
I tried to import GetTickCount() inside the Kernel32.DLL with the import macro.
I did it as always and tried to call the function with invoke. But this time
it didn't work because GetTickCount() doesn't use parameters. So I tried "call".
FASM compiled but when I run my compiled program, it seems to crash at
the point where I call GetTickCount().
What could be the reason?

And there's another thing: I asked about already but didn't get a real answer.
I tried to learn it on my own but I still understand nearly NOTHING about
this calling-conventions! I know there's a C-Calling-Convention and I know
how it gets used (push params in reversed order and call), but what about
other calling conventions? Why do they exist and when do they get used (
I heared about PASCAL calls and so on)?
What convention is used when I use "call" or "stdcall"? Or invoke?? Is invoke
the same as call and stdcall? Cinvoke is C-Call I think?

PLEASE HELP ME Sad
Post 06 Jan 2005, 16:40
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Jan 2005, 20:16
why "call", just use "invoke GetTickCount" without any arugments and it should work. Anyway, you can call it youself by "call [GetTickCount]" (because "invoke something" is "call [something]", that's why it crashed)
Post 06 Jan 2005, 20:16
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial 06 Jan 2005, 20:28
No Invoke GetTickCount doesn't work! But call [GetTickCount] did work! But I don't understand something: When I write an own function with proc/endp, I have to call it through "call Progname" and not "call [Progname]"... oO What's the matter?

And please help me with my other questions... I really need to know it.
Thank you.
Post 06 Jan 2005, 20:28
View user's profile Send private message Reply with quote
msmith



Joined: 22 Jun 2003
Posts: 40
Location: Missouri
msmith 06 Jan 2005, 23:15
Here is a copy/paste from my program. This code works fine every day.

Code:
invoke GetTickCount
mov [_Tmp1],eax
    


Here are 2 C style calls which work fine also.

Code:
cinvoke ltoa,eax,[_ConvBuf1],10
...
cinvoke system,[_IOBuffer]
    
Post 06 Jan 2005, 23:15
View user's profile Send private message Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 06 Jan 2005, 23:18
because if you call an import then

invoke addr makes call [addr]
the import is just pointer to exported function; addr= pointer to dll

if you make function ,it has own address not pointer to the address so you call addr
addr = proc

if you type invoke it means for example call [00041000]
and data placed under this address can jumps to the forbidden addres which has no access to execute.

every is clear?

_________________
Microsoft: brings power of yesterday to computers of today.
Post 06 Jan 2005, 23:18
View user's profile Send private message Reply with quote
msmith



Joined: 22 Jun 2003
Posts: 40
Location: Missouri
msmith 06 Jan 2005, 23:21
BTW, here is the cinvoke stuff I used in the previous post.

Code:
;declares a cdecl procedure
macro cproc name,[params]
{
   common
      name:
   push ebp
    mov ebp, esp            
    
    virtual at ebp +8                 

      if ~ params eq    
          forward
                     local ..params          
                    ..params dd ?
                       params equ ..params
         common
      end if
      end virtual
 local ..dynamic_data,..dynamic_size
 dynamic_data equ ..dynamic_data
     dynamic_size equ ..dynamic_size
     virtual at ebp - dynamic_size
       dynamic_data:
}

macro center
{       
            dynamic_size = $ - dynamic_data
   end virtual
   sub esp,dynamic_size
}

macro cret
{      
    add esp,dynamic_size
        pop ebp
     ret     
}

;calling/ invoking a cdecl procedure

macro ccall proc,[arg]            ; call cdecl procedure
{ 
   common
              local ..param_num 
          ..param_num=0           
    reverse
             push arg
            ..param_num = ..param_num + 4           
    common
              call proc 
          add esp, ..param_num            
}

macro cinvoke proc,[arg]              ; invoke cdecl procedure (indirect)
{
       common
              if ~ arg eq
                         ccall [proc],arg
            else
                        call [proc]
 end if 
}
    
Post 06 Jan 2005, 23:21
View user's profile Send private message Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial 07 Jan 2005, 11:26
Thank you for all your answers. Except the calling-conventions, everything is clear now. However, "invoke GetTickCount" I can't use because FASM gives me errors. I'm confused about. But however, I can use call and understand the system now.

Thank you very much. And if someone knows about calling-conventions, I would be glad for a further answer.
Post 07 Jan 2005, 11:26
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.