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
 

Calling a Dynamic Link Library from Visual Basic, VB - assembler integration through a DLL

sachin22
Quote Post


New Member
*

Group: Members
Posts: 5
Member No.: 1319
Joined: 9-June 05


Hello everybody,

I am still learning MASM32, I am trying to return a string in my .DLL but I get and "out of memory" error in Visual Basic.
The GetNewTempFile proc is causing problems for me.

Could you help me please?

Thank you.

Attached File ( Number of downloads: 19 )
 Login or Register to download
PMEmail Poster
Top
shoorick
Quote Post


Extremely Active Member
******

Group: Admins
Posts: 2301
Member No.: 160
Joined: 22-June 04


Hi!
The aforementioned procedure works without any problems in the code you attached.

I dont have Visual Basic, and never worked with it, so i can't help you more with this.

Regards!

Attached File ( Number of downloads: 24 )
 Login or Register to download
PMEmail PosterUsers Website
Top
swallon
Quote Post


New Member
*

Group: Members
Posts: 7
Member No.: 1120
Joined: 17-March 05


Visual Basic does not support pointers.
PMEmail Poster
Top
akyprian
Quote Post


Administrator
******

Group: Admins
Posts: 2307
Member No.: 1
Joined: 12-May 04


Pointers can be used in Visual Basic, but this is an advanced (and tricky) topic.

I guess, this is not exactly what sachin22 asks...

Try ByRef (not ByVal) when you make the call from Visual Basic.

If you still have problems, upload a VERY small .dll WinAsm Studio project and a Visual Basic executable project, so that I can quickly help you solve the problem.

Antonis
PMEmail PosterUsers Website
Top
sachin22
Quote Post


New Member
*

Group: Members
Posts: 5
Member No.: 1319
Joined: 9-June 05


Hi guys,

Thanks a lot for your response.
I was able to return a string by using SysAllocString to be used as:

CODE
dim x as string

x=asmReturnAString()


This works fine, as for passing by reference is concerned, I was only able to copy from parameter 1 to parameter2 as follows in MASM32:

CODE
asmStringByRef proc lpString:LPCTSTR,lpRetByRef:LPCTSTR

; Proc works if lpString is declared as LPSTR/LPCTSTR/DWORD and
; lpRetByRef declared as ptr dword/dword/LPSTR,even LPCTSTR

   mov esi, dword ptr [lpString]
   mov edi, dword ptr [lpRetByRef]

@label:

   mov al, [esi]
   inc esi
   mov byte ptr [edi],al
   inc edi
   cmp al,0
   jne @label
 
   Ret

asmStringByRef EndP


...in Visual Basic:

CODE
Private Declare Sub asmStringByRef Lib "C:\asmICLogix.dll" (sVal As String, sRef As String) ' As Long

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' asmStringByRef test results
' p1 -> p2:  byRef->ByRef
'
' p1 : DWORD/LPSTR/LPCTSTR
' p2: ptr dword/dword/LPSTR,even LPCTSTR
'
' Quotes accepted on p1 for asmStringByRef
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Test ()

Dim s As String, z As String

  z = "ICLrpt1.tmp"
  Call asmStringByRef(z, s)
  MsgBox s

End Sub


My asmGetNewTempFile proc does not return the string in parameter strNewFileName:

CODE
asmGetNewTempFile proc strPrefix :DWORD, strNewFileName:BYTE

   ; strPrefix was originally LPCTSTR, works even if DWORD
   ; param1:DWORD, param2:PTR DWORD works, param1:LPSTR,param2:PTR DWORD works


   ;; pass LPCTSTR directly
 
   local strFullPath[256]:byte
   invoke GetTempPath, 256, addr strFullPath; contains path only
   invoke lstrcat, addr strFullPath,strPrefix

   invoke CreateFile, addr strFullPath, GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE,\
       NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_DELETE_ON_CLOSE, NULL

   lea eax,strFullPath
   mov edx,0

@label:

   mov al,byte ptr [strFullPath+edx]
   mov byte ptr [strNewFileName+edx],al
   inc edx
   cmp al,0
   jne @label
   ret

asmGetNewTempFile EndP


I would like to know what changes are needed to support byVal in vb and how to make strNewFileName return a string by reference.

I am still learning, so your help will be much appreciated, even on the other procs contained in the project.

Kindly test the dll for me, I hope it is not heavily bugged.
Thanks a lot for your help, keep the good job going.

Sachin.

Attached File ( Number of downloads: 21 )
 Login or Register to download
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