News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

How to call function in DLL?

Started by garyhess, September 21, 2012, 12:47:45 AM

Previous topic - Next topic

garyhess

I've been using the Easy Code Visual IDE with GoAsm for about two months and have managed to create a number of small programs (solutions to first ten Project Euler problems).

Now I'm trying to move onto my first substantial project but I need to call some functions in an external DLL (not part of Windows). It's not working though, so I was wondering if anyone could point me to a tutorial (or code example) somewhere that shows how to invoke an external DLL?

I've linked the DLL in my project ("tqsllib2.dll") and am trying the following:


Invoke tqslinit (tqsllib2.dll)


The error I get from Easy code is:


Error!
The following symbol was not defined in the object file or files:-
tqslinit
Output file not made


Thanks,
Gary

garyhess

Sorry, it works...I misspelled the function name. Should be "tqsl_init".

:icon_confused:

Vozzie

 :t, I just finished making a EasyCode MASM32v11 example for you ,...

garyhess

Hi Vozzie,

Many thanks for the fast help! I'm using GoAsm instead of MASM so it doesn't compile directly, but the idea is clear.

I'm now getting into the DLL and executing some simple functions. However, I've run across another problem: I need to define a data structure (object) that is used in the DLL. I have a file "tqsllib.h" that defines the data structure like this:


/** Certificate provider data */
typedef struct tqsl_provider_st {
char organizationName[TQSL_NAME_ELEMENT_MAX+1];
char organizationalUnitName[TQSL_NAME_ELEMENT_MAX+1];
char emailAddress[TQSL_NAME_ELEMENT_MAX+1];
char url[TQSL_NAME_ELEMENT_MAX+1];
} TQSL_PROVIDER;


How I can include this file in my EasyCode project so it will understand the data structure? Under "Project" there is "Add include files *.inc, *.h", but when I try this function it only allows me to include a "*.inc" file (and not "*.h").

I'm pretty new to Win32 programming so I am confused.

Thanks again!
Gary

Vozzie

Hi,

To add a include file in EasyCode you create the include file with notepad inside the project directory. Then you choose "Add files", and in the open file dialog there's a dropdownlist you are able to change the extension filter type from ".asm" into ".inc". Then you are able to select the include file and add it to your project... (I think the "Add include" file menu only works for the include files in your assembler environment's "inc" directory.)

The structure in an include file (for EasyCode Masm) could look like this,...

; include only once
IFNDEF MYINCLUDEFILE_INC
MYINCLUDEFILE_INC Equ <1>

; Look up the real value of TQSL_NAME_ELEMENT_MAX and replace 1234 with the correct value
TQSL_NAME_ELEMENT_MAX Equ  1234

TQSL_PROVIDER Struct
     organizationName DB  TQSL_NAME_ELEMENT_MAX + 1 Dup(?)
     organizationalUnitName DB  TQSL_NAME_ELEMENT_MAX + 1 Dup(?)
     emailAddress  DB  TQSL_NAME_ELEMENT_MAX + 1 Dup(?)
     url  DB  TQSL_NAME_ELEMENT_MAX + 1 Dup(?)
TQSL_PROVIDER EndS

ENDIF ; IFNDEF MYINCLUDEFILE_INC


I don't use EasyCode with GoAsm so there can be some (small) differences between what i wrote and your environment,...

garyhess

Hi Vozzie,

OK, that looks very useful. I will try it tomorrow.

I also stumbled across this feature of GoAsm: http://www.godevtool.com/GoasmHelp/GoAsm.htm#struc

The syntax for defining structures is there so I can probably use that.

Gary

garyhess

OK, this works in GoASM:


.Data

; ...
TQSL_PROVIDER_ST Struct
organizationName DB 101H Dup 0
organizationalUnitName DB 101H Dup 0
emailAddress DB 101H Dup 0
url DB 101H Dup 0
EndS
provider TQSL_PROVIDER_ST

.Code

; ...
Invoke MessageBoxA, [hWnd], Addr provider.organizationName, 'LotW Test 1', MB_OK



So I'm able to define the corresponding structure in GoASM, which is very useful. But my uninformed mind is wondering if there's not a way to just directly import these definitions from the file with the TYPEDEFs. Is that possible somehow?

Gary

Vozzie

Hi,

If you mean add a header file to a EasyCode project, i guess not... But there are translator tools to translate headers into include files. Recently i downloaded h2inc but i didn't try it yet,... I still have to find out but i think that this tool* does the same,... (As far as they will translate correct into your assembler's syntax i don't know either)

btw: before it's too late, EasyCode and Assembler are very addictive, be warned :) ...

Greetings

wjr

The link to my webpage on the left here will get you to my xlatHinc which provides a translation suitable for GoAsm.

garyhess

@Vozzie: It's too late for me, already addicted  8)

@ wjr: I was thinking I could write a Perl script to convert the header file but looks like you have already done the job! Thanks, that will save me time.

I'm also checking out your skeleton Windows examples. I'm just beginning to learn Win32 and am finding the going a bit rough. I'm using the Easy Code IDE and there is a great tutorial on getting started with Easy Code/Assembler/Win32 (http://www.easycode.cat/English/Tutorial.htm). I'm not sure how to get to the next level with Windows though ... but I guess I need to just try to build some small apps with a few Win32 controls.

Gary