flat assembler
Message board for the users of flat assembler.
Index
> Windows > FASM, DLL problem |
Author |
|
ProMiNick 18 May 2019, 17:34
Thou wil be laught, but thour enemy is one line of thour code:
Code: local buf:DWORD |
|||
18 May 2019, 17:34 |
|
revolution 18 May 2019, 19:33
Yes, You defined "buf" twice. The most recent definition will win and you are reading from an uninitialised local variable on the stack.
|
|||
18 May 2019, 19:33 |
|
Tomasz Grysztar 18 May 2019, 20:12
BTW, when trying to assemble the same source with fasmg (and its fasm-compatible Windows headers), it does signalize the problem precisely.
|
|||
18 May 2019, 20:12 |
|
pitchblack 19 May 2019, 06:31
Hmmm..... thanks guys, I'll try it immediately, though I've already tried it without the initialization of 'buf' before - but just for "you never know".
Problem before was that if I didn't initialized 'buf', either as local or a global, I couldn't see that anything got transfered. Anyway, will try again |
|||
19 May 2019, 06:31 |
|
pitchblack 19 May 2019, 07:33
Well .... I removed the local buf:DWORD so it's just proc Blow buf -didn't work
I tried proc Blow buf:DWORD as well -didn't work. Then I replaced eax with ebx (as buf probably is equal to eax), that didn't work either. Also, the fld1 doesn't return anything but that's a minor concern at the moment. If I can get that buffer thing to work, I won't need to be able to return anything. |
|||
19 May 2019, 07:33 |
|
revolution 19 May 2019, 09:00
Show us how you are calling it.
The fld1 is useless, so removing that is okay. Replacing eax with ebx might be bad if your calling function expects ebx to be preserved. Otherwise eax should be fine. |
|||
19 May 2019, 09:00 |
|
sinsi 19 May 2019, 09:10
What is your code for calling the Blow proc?
|
|||
19 May 2019, 09:10 |
|
pitchblack 19 May 2019, 14:53
Well, there's not really much code to show - the call comes from the Game Maker Studio Extension, so I just put in the relevant info. I have no idea how it is doing the calling, but I assume it's more or less standard procedure, as others have no problem in either C++ or asm - in asm's case it was made in MASM.
Both tests were exactly like mine. I'd have taken a screenshot of it, but no easy way to insert pics here, so I'll just tell it: There are 6 inputs 1 the function name INSIDE Game Maker - the name we use when using the function in GML (Game Maker Language) 2. The exported name - the function name that GML will use to call the function in the DLL 3. An info text that shows when you type the function inside GML 4. Returning param of the function (Either a String or a Double) 5. The calling method (STDCALL or CDECL) 6. Parameters to hand over to the function - can be up to 7 - It's either a String or a Double - for a pointer we should use string. So my inpust are just 1. blow 2. Blow 3. blow(ptr) - not relevant really in this 4. Double 5. STDCALL 6. String So in the GML I just write a=blow(buffer_address) And straight after I check the buffer's values and they are exactly the same as before I called the function. Even the 'a' value which is just zero. Here's a link to the subject on the other forum, where you all can see both the C version and ASM version in more details. https://forum.yoyogames.com/index.php?threads/assembler-gms-1-4-and-dll.62941/ |
|||
19 May 2019, 14:53 |
|
revolution 19 May 2019, 15:05
I notice the original MASM code uses "RET 0" so that would suggest it is a CCALL function.
By default fasm uses STDCALL for functions unless you specify "ccall" in the proc definition. Code: proc ccall Blow buf
;... |
|||
19 May 2019, 15:05 |
|
pitchblack 19 May 2019, 15:12
revolution wrote: I notice the original MASM code uses "RET 0" so that would suggest it is a CCALL function. Right on it to do some testing though not sure it's the problem (but Far from expert on that subject ). I've tried it before with changing call methods, but there probably was other things in the test code at that time. This time I just do it as simple as possible without messageboxes and so on. But I noticed in the code that it states STDCALL at the beginning, so I assumed it was that - but but but ...... one never know |
|||
19 May 2019, 15:12 |
|
fasmnewbie 19 May 2019, 18:23
Your DLL can't have empty fixups/pointers in the relocation section. Change it to something like this;
Code: section '.reloc' fixups data readable discardable if $=$$ dd 0,8 ;dummy values end if "readable" flag is required. |
|||
19 May 2019, 18:23 |
|
pitchblack 19 May 2019, 18:47
fasmnewbie wrote: Your DLL can't have empty fixups/pointers in the relocation section. Change it to something like this; I will try that as well - the changing of call method in either fasm or game maker didn't help, which I expected really ..... from my knowledge all it does is letting the caller clean up the stack frame |
|||
19 May 2019, 18:47 |
|
bitRAKE 19 May 2019, 18:47
All the abstraction and work arounds for the abstractions are causing undue confusion, imho. The routine is just:
Code: dll_test: mov eax,[esp+4] ; do something with the address retn _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
19 May 2019, 18:47 |
|
pitchblack 19 May 2019, 18:58
Ok, changing the '.reloc' Did provide some other result - now game maker crashes
|
|||
19 May 2019, 18:58 |
|
fasmnewbie 19 May 2019, 19:27
That's good. That means you have other issues to attend to because having empty fixup doesn't crash your program. Try simple test case just to see how DLL works?
Code: //test.c //gcc -m32 test.c mydll.dll -o test.exe #include <stdio.h> extern int Blow(); int main() { printf("Return value is %d\n",Blow()); //should return -3 return 0; } Your simple DLL... does nothing but to return -3 in EAX Code: ;mydll.asm format PE DLL entry DLLEntryPoint include 'win32a.inc' section '.code' code readable executable proc DLLEntryPoint hinstDLL,fdwReason,lpvReserved mov eax,TRUE ret endp proc Blow c mov eax,-3 ;test return value ret endp section '.edata' export data readable export 'mydll.dll',Blow,'Blow' section '.reloc' fixups data readable discardable if $=$$ dd 0,8 ;dummy values end if |
|||
19 May 2019, 19:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.