hello,
i have my source code devided into two parts:the main module and a static library (.lib),i include the .lib library in my main program using:
includelib my_lib.lib
i have the following public variable:
szMyString db MAX_PATH dup(0)
in the .lib library , i used the following:
EXTERNDEF szMyString:byte
is it right?or should i use:
EXTERNDEF szMyString:ptr byte
thank you
ptr byte - it's pointer of dword, so is need to use byte :dazzled:
You would use: EXTERNDEF szMyString:BYTE
I did a quick test:
test.asm
.686
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE
INCLUDE windows.inc
INCLUDE kernel32.inc
INCLUDE user32.inc
INCLUDE msvcrt.inc
INCLUDE masm32.inc
INCLUDE c:\masm32\macros\macros.asm
INCLUDELIB kernel32.lib
INCLUDELIB user32.lib
INCLUDELIB msvcrt.lib
INCLUDELIB masm32.lib
EXTERNDEF Pi:REAL10
EXTERNDEF szName:BYTE
EXTERNDEF szPress:BYTE
.CODE
start:
finit
fldpi
fstp Pi
INVOKE StdOut, real10$(Pi)
INVOKE StdOut, chr$(13,10)
INVOKE StdOut, ADDR szName
inkey ADDR szPress
INVOKE ExitProcess, 0
END start
test2.asm
.686
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE
EXTERNDEF Pi:REAL10
EXTERNDEF szName:BYTE
EXTERNDEF szPress:BYTE
.DATA
Pi REAL10 0.0
szName BYTE "Greg",13,10,0
szPress BYTE 13,10,"Press any key to exit ... ",0
END
test.rsp (linker response file)
/DEBUG
/SUBSYSTEM:CONSOLE
/INCREMENTAL:NO
/LIBPATH:C:\MASM32\LIB
/OUT:test.exe
test2.obj
yes, when the calling function does not need the sizeof the string (in our examlpe szMyString),there is no problem,,,,but when you call a function that needs the sizeof the string it is a problem, because the sizeof szMyString equals to one (sizeof byte==1)
invoke LoadString,hInstance,100,addr szAppName,sizeof szAppName
this line is in the .lib library where we had declared szMyString as
EXTERNDEF szMyString:byte
sizeof could control only assembler, so this value is need to put to inc-file and use as constant, because even in high level languages extern is only labels in data and code segments. :cheekygreen:
yes Adamanteus,this is what i am using now in my projects,
so i asked if there is a way to do sizeof instead of a constant (maybe declared in inc file),
it seems to be impossible to do this,
thank you for your help.
ossama,
Use lstrlen.
hi Greg,
you can not use lstrlen in functions that need the maximum size of a buffer not the length of that buffer,for example the function GetWindowText needs an address of buffer to receive the window text and the maximum number of bytes to use in that buffer
Quote from: Greg on December 15, 2007, 08:56:06 PM
You would use: EXTERNDEF szMyString:BYTE
Yep.
Quote from: ossama on December 16, 2007, 10:27:55 AM
invoke LoadString,hInstance,100,addr szAppName,sizeof szAppName
LoadString takes the length of the buffer, not the length of the string.
Quote
nBufferMax
[in] Specifies the size of the buffer, in TCHARs. This refers to bytes for ANSI versions of the function or WCHARs for Unicode versions. The string is truncated and NULL terminated if it is longer than the number of characters specified.
Allocate your buffer of MAX_PATH bytes then use that buffer to read your string.
You really need to post more code...deciphering what you want is giving me a headache. :(
QuoteLoadString takes the length of the buffer, not the length of the string.
My mistake, I should have looked at it closer.