flat assembler
Message board for the users of flat assembler.

Index > Windows > TCHAR access in Windows structures ...

Author
Thread Post new topic Reply to topic
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 23 May 2012, 15:51
Sorry, need some help, fighting with Windows and following structure;

typedef struct _DEV_BROADCAST_PORT {
DWORD dbcp_size;
DWORD dbcp_devicetype;
DWORD dbcp_reserved;
TCHAR dbcp_name[1];
} DEV_BROADCAST_PORT, *PDEV_BROADCAST_PORT;

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363248%28v=vs.85%29.aspx

How can I access dbcp_name (show the name in a message box) ?

Quote:

dbcp_name

A pointer to a null-terminated string specifying the friendly name of the port or the device connected to the port. Friendly names are intended to help the user quickly and accurately identify the device—for example, "COM1" and "Standard 28800 bps Modem" are considered friendly names.



Tried to define this way:

Code:
struct DEV_BROADCAST_PORT
  dbcp_size             dd ?
  dbcp_devicetype       dd ?
  dbcp_reserved         dd ?
  dbcp_name             dd ?
ends   

        mov     ebx,[lparam]
        virtual at ebx
        dbp     DEV_BROADCAST_PORT
        end     virtual
        invoke  MessageBox,[hwnd],[dbp.dbcp_name],_caption,MB_ICONERROR+MB_OK
    


But this kills my application.
Other "definitions" I tried are not accepted by FASM.

One additional hint:

Quote:

dbcp_name is not a pointer
The dbcp_name member is not a pointer. This is a variable-length structure, and dbcp_name is an array that contains the actual characters of the port name.


So this seems to be an error in the documentation.

Thanks. Wink
Post 23 May 2012, 15:51
View user's profile Send private message Send e-mail Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1671
Location: Toronto, Canada
AsmGuru62 23 May 2012, 16:02
Maybe this way:
Code:
        mov     ebx,[lparam] 
        lea      eax, [ebx + DEV_BROADCAST_PORT.dbcp_name] 
        invoke  MessageBox,[hwnd],eax,_caption,MB_ICONERROR+MB_OK 
    
Post 23 May 2012, 16:02
View user's profile Send private message Send e-mail Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 23 May 2012, 17:33
Thanks AsmGuru,

the following worked:

Code:
struct DEV_BROADCAST_PORT
  dbcp_size             dd ?
  dbcp_devicetype       dd ?
  dbcp_reserved         dd ?
  dbcp_name             db ?
ends

        mov     eax,[lparam]    ; pointer to DEV_BROADCAST_PORT structure
        add     eax,12
        invoke  MessageBox,[hwnd],eax,_caption,MB_ICONERROR+MB_OK
    


Is strange that the pointer is not accessible.
dbcp_name is the first character of a null terminated string.
Sometimes you can get nuts what's going on in the brain of Microsoft developers. Rolling Eyes
By the way in my case it is representing a 4 character string ( "COM4" ).
Post 23 May 2012, 17:33
View user's profile Send private message Send e-mail Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1671
Location: Toronto, Canada
AsmGuru62 23 May 2012, 21:11
DEV_BROADCAST_PORT.dbcp_name is actually at offset of 12 bytes, so it should have worked too.
Post 23 May 2012, 21:11
View user's profile Send private message Send e-mail Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 23 May 2012, 21:35
Yes I know, don't like to use lea when I can use add instead.
Anyway strange syntax to use a structure for non structured data (variable length of structure content).
Post 23 May 2012, 21:35
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.