I'm a newbie learning assembler and the Win32 API. I'm trying to play with SID numbers and group names. I want to call "ConvertSidToStringSid" but it's not defined in ADVAPI32.LIB. Can I call the real ADVAPI32.DLL and call the function directly by address? If so, how? :confused:

I realize I could just write my own function, but I want to learn more about the existing API.
Posted on 2001-08-29 12:19:57 by SarkOfManyHats
Search this Messageboard for "GetProcAddress" and you'll find a nice example by comrade, how to use it.
Posted on 2001-08-29 12:49:04 by bazik
Wouldn't it be smarter to implicitly link the DLL? Include the advapi32.lib
(import library), and whatever header file is necessary... that should
be enough. You shouldn't be messing with GetProcAddress when
you don't need it.
Posted on 2001-08-29 14:09:08 by f0dder

Yes, it would be wonderful to just include the LIB and INC files. However, it seems this is a new function for Windows 2000 that is not included in the LIB/INC files in the MASM32 package. That's the source of my problem.;)
Posted on 2001-08-29 14:23:24 by SarkOfManyHats
Another solution: Use a decent Assembler. Example, in SpAsm syntax

> call 'Advapi32.ConvertSidToStringSid' .......

needs no lib, no inc, no nothing.
(SpAsm V.3.03c posted yesterday): http://betov.free.fr/SpAsm.html

Posted on 2001-08-30 03:16:07 by Betov

The libraries in MASM32 are from win98, get the platformsdk and use them in MASM32, you will have to create a new set of include files using the supplied utility "l2inca".

Then you can play with a REAL assembler that uses libraries, include files, modules and all of those things that some people would try and keep you away from. :)


Posted on 2001-08-30 08:05:57 by hutch--
I got the Platform SDK version of ADVAPI32.LIB and used L2incA.exe to create the include file. The code will compile, but it crashes every time. I haven't had time to learn debugging, so I thought I would post the code and let the community find the problem.


; MySid
; This program displays your SID
; (Security ID) in a message box.

.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\advapi32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\masm32.lib

; function declaration structure

MsgCaption db "MySid", 0
MsgSidStart db "Your SID is '", 0
MsgSidEnd db "'.", 0
MsgInvalidSid db "invalid", 0
MsgMemory db "insufficient memory", 0
MsgNotFound db "not found", 0
hCurrentThread dd 0
hAccessToken dd 0
hCurrentProcess dd 0
dwInfoBufferSize dd 0
pSid dd 0

szSid dw ?

invoke GetMySid, addr pSid ; populates buffer with sid

invoke IsValidSid, addr pSid ; test
.if eax == 0
invoke szCatStr, addr MsgSidStart, MsgInvalidSid

invoke ConvertSidToStringSid, addr pSid, addr szSid

.if eax == 0
invoke LocalFree, addr szSid
invoke szCatStr, addr MsgSidStart, MsgNotFound
invoke LocalFree, addr szSid
invoke szCatStr, addr MsgSidStart, MsgMemory
invoke LocalFree, addr szSid
invoke szCatStr, addr MsgSidStart, addr szSid
invoke szCatStr, addr MsgSidStart, addr MsgSidEnd
invoke MessageBox, NULL, addr MsgSidStart, addr MsgCaption, MB_OK
invoke ExitProcess, eax
; end main code

; subroutine/function to retrieve SID structure
; try to retrieve Access Token from current thread
invoke GetCurrentThread
mov hCurrentThread, eax
invoke OpenThreadToken, hCurrentThread, TOKEN_QUERY, TRUE, ADDR hAccessToken
.if eax == 0
; no Access Token from Thread, make attempt from current process (application)
invoke GetLastError
.if eax != ERROR_NO_TOKEN
invoke GetCurrentProcess
mov hCurrentProcess, eax
invoke OpenProcessToken, hCurrentProcess, TOKEN_QUERY, ADDR hAccessToken
.if eax == 0
invoke GetLastError
; retrieve SID structure from TokenOwner class of Access Token
invoke GetTokenInformation, hAccessToken, TokenOwner, lpSid, NULL, ADDR dwInfoBufferSize
.if eax == 0
invoke GetLastError
.if dwInfoBufferSize > 0
invoke GlobalAlloc, GMEM_FIXED, dwInfoBufferSize
mov pSid, eax
invoke CloseHandle, hAccessToken
mov eax, 0
GetMySid endp
end start

Thanks in advance for your help!
Posted on 2001-09-07 14:05:05 by SarkOfManyHats