flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
baldr 15 Jan 2009, 21:05
Alexander,
What did you mean by export? Implement structure similar to BSTR? Code: struc BSTR [data] { common local length dd length label . word forward du data common length = $ - . dw 0 } ![]() BTW, were you really want BSTR of single diamond, or that was ASCII end-of-tape? ![]() _________________ "Don't belong. Never join. Think for yourself. Peace." – Victor Stone. |
|||
![]() |
|
Alexander 15 Jan 2009, 21:14
Thank you baldr.
I see... I've to implement a structure, but forgive me my question: I'm a newbe to fasm, so how is it possible to reach my goal? Could you please give me a "complete" example of who to export a function in a dll which returns a BSTR or a pointer to BSTR, containing any data eg. "test"? Please |
|||
![]() |
|
baldr 15 Jan 2009, 21:23
Alexander,
BSTR is a pointer. What kind of a complete example do you need? Define static data with BSTR macro (like, mystr BSTR "Hello, world!", 13, 10), return mystr… |
|||
![]() |
|
Alexander 15 Jan 2009, 21:29
Okey now I now how it works with static data, but is it also possible with dynamic creation of that data. Is it possible to create the data in a function in the code segement?
Thank you, baldr, for your expertise. Alexander |
|||
![]() |
|
baldr 15 Jan 2009, 21:46
Alexander,
1. Allocate big enough memory range. 2. Copy contents. 3. Set size and terminator. 4. Return pointer. Which part of the scheme is difficult? |
|||
![]() |
|
Alexander 15 Jan 2009, 21:53
Baldr,
thank you for your answer. I'm absolutly new to fasm, so thank you for your patience. How do I master this all? Would you please be so kind to give me an example? I've nothing found in fasm documentation. Thank you Alexander |
|||
![]() |
|
baldr 15 Jan 2009, 22:58
Here is the sample code:
Code: format PE include "WIN32WX.INC" .code start: invoke GetProcessHeap mov [hBSTRHeap], eax stdcall SysAllocString, "Hello, world!" ret proc SysAllocString sz mov eax, [sz] test eax, eax jz .done ; got NULL, bail out invoke lstrlen, [sz] test eax, eax jz .done ; got zero-length string, bail out shl eax, 1 ; they're 2-byte push eax ; save string size add eax, 4+2 ; length+terminator invoke HeapAlloc, [hBSTRHeap], HEAP_ZERO_MEMORY, eax test eax, eax jz .done ; no core, bail out; extra dword at stack will be discarded, believe me |
|||
![]() |
|
Alexander 15 Jan 2009, 23:09
Wow, baldr, I tried it out and tested it with IDA. Amazing!!!
Thank you very much and thank you for your time! |
|||
![]() |
|
baldr 15 Jan 2009, 23:19
Alexander,
The code definitely could be written better, but duty calls… so it's quick'n'dirty. ![]() |
|||
![]() |
|
Alexander 27 Jan 2009, 17:17
Hello baldr,
your dynamic example worked perfectly. I think I must be to stupid because I tried to declare the structure and to define "mystr BSTR ..." as you wrote, but if I want to return the string, the vb6 application from which I call the fasm win32 dll crashes? ![]() Isn't the following correct: Code: mov eax, [mystr] ret or Code: mov eax, mystr
ret I also tried to change the du in the structure to db, because I thought that VB6 has problems with it. (But VB6 is Unicode-ready)? So baldr, please, where is the mistake? baldr wrote:
|
|||
![]() |
|
Alexander 04 Feb 2009, 15:30
bladr?
Or anyone who can help me please? ![]() ![]() ![]() Alexander |
|||
![]() |
|
Yardman 04 Feb 2009, 15:49
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 03:28; edited 1 time in total |
|||
![]() |
|
Alexander 04 Feb 2009, 17:10
Yardman wrote: Can you show us DLL code and VB code? The DLL-Code Code: format PE GUI 4.0 DLL entry DllEntryPoint section '.code' code readable executable struc BSTR [data] { common local length dd length label . word forward du data common length = $ - . dw 0 } mystr BSTR "Hello, world!", 13, 10 proc BStr_Generator mov eax, [mystr] ret endp proc DllEntryPoint, hinstDLL,fdwReason,lpvReserved mov eax,TRUE ret endp include "idata.inc" section '.edata' export data readable export 'ERRORMSG.DLL',\ BStr_Generator, 'BStr_Generator' idata.inc Code: section '.idata' import data readable writeable library kernel32,'kernel32.dll',\ user32,'user32.dll' import kernel32,\ FormatMessage,'FormatMessageA',\ GetLastError,'GetLastError',\ LocalFree,'LocalFree' import user32,\ MessageBox,'MessageBoxA' In Visual Basic 6 - GUI Win32-Application (should display a MessageBox with the string) Code: Private Declare Function BStr_Generator _ Lib "Test.dll" _ () As String Private Sub Form_Load() MsgBox (BStr_Generator()) End End Sub Any help would be nice! ![]() |
|||
![]() |
|
Alexander 04 Feb 2009, 17:49
baldr or Yardman? Anyone?
Where's the mistake |
|||
![]() |
|
Yardman 04 Feb 2009, 18:51
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 03:28; edited 1 time in total |
|||
![]() |
|
Alexander 04 Feb 2009, 19:40
Yardman wrote: Alexander, Hi Mark, the problem is in IDA everything is perfect, but when I return to VB6 (the same problem occurs when I use .NET - .NET internally uses BSTRs) the application crashes. I've been playing around for hours (days), but I can't get rid of the problem!? ![]() In the article they allocate the string bstrUpperCase dynamically by calling the function SysAllocStringByteLen, doing some manipulation and returning the BSTR, but the difference between my code is that the len has already been allocated by the compiler and I just want to return the BSTR. Why is my version not working? I would be glad for any suggestions. Thanks ![]() Alexander |
|||
![]() |
|
bitRAKE 05 Feb 2009, 05:27
Windows must be able to control the (de-)allocation of the string. Use the OLE string functions to create/use BSTRs - it is the easiest way to insure it will work.
Quote: To handle strings that are allocated by one component and freed by another, Automation defines a special set of functions. These functions use the following data type: typedef OLECHAR * BSTR; |
|||
![]() |
|
Alexander 05 Feb 2009, 23:03
bitRAKE wrote: Windows must be able to control the (de-)allocation of the string. Use the OLE string functions to create/use BSTRs - it is the easiest way to insure it will work. bitRAKE, thanks for your answer, but how will any ole function or api know that the string wasn't manipulated. Isn't there a way in fasm for a solution? Thanks Alexander |
|||
![]() |
|
bitRAKE 06 Feb 2009, 02:13
Alexander wrote: how will any ole function or api know that the string wasn't manipulated. Isn't there a way in fasm for a solution? I am by no means very experienced with COM/BSTR, but I've seen other's struggle with the same problem on the MASM forums in years past. Japheth has done much with COM in assembly, but the code has much MASM specific syntax glue holding it all together (i.e. tough reading for a MASM noob). IronFelix's recent posting looks much better by comparison, but lacks the depth of Japheth's work. (I'm being my typical overcritical ass - hope they don't take it personal, both are great work.) |
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.