Jump to content

Problem with Struct


anka
 Share

Recommended Posts

Hi everyone

My problem is that I need to store only a flag (True/False) in a Dword. Hove do I accomplish that?

GetCommState in Kernell32.dll (from MSDN) uses a "DCB" looking like this:

typedef struct _DCB {

DWORD DCBlength;

DWORD BaudRate;

DWORD fBinary :1;

DWORD fParity :1;

DWORD fOutxCtsFlow :1;

...

WORD wReserved1;

} DCB, *LPDCB;

the "DCB" is created using:

DLLStructCreate("DWord;DWord;DWord;DWord;DWord;DWord;....")

Baudrate is retreived as it should, but the rest is filled up in just a few varibles:

(this is the result from dllcall GetCommState)

DCBlength 28

Baudrate 1200

fBinary 4113 <--- This should only contain a flag (true/false)

fParity 134217728 <--- same here and so on...

fOutxCTSFlow 459264

fOutxDSRFlow 1249536

fDTRControl 0

fDsrSensitivity 0

...

I hope I have made my self understandable?

I have searched both the help and in the forums but not found any thing that could help me. Is it possible to fix my problem in any way?

thx in advance

anka

PS AutoIT Rocks

Link to comment
Share on other sites

dword is not a real flag but 1 is 1, 0 is 0

just set the value witl DLLStructSetDatat($struct,2, 1) for setting the second dword to 1. :P

Thx for the reply.

I don't use DLLStructSetData. I get the value from a DLL by using dllcall. The DLL uses a Dword as a flag.

the DLL uses something like this in VB:

typedef struct _DCB {

DWORD DCBlength;

DWORD BaudRate;

DWORD fBinary :1; <---- I understand this like it only uses one bit in the Dword, just to use it as a flag

DWORD fParity :1; <---- same here...

But to my knowledge it is not possible to do that in AutoIT. And It has no available "Bit" varible either.

So does anyone have an idea?

/andreas

Link to comment
Share on other sites

if you use DLLStructCreate to reserve memory as you describe you can use DLLStructData as I mention.

Now you have to call the GetCommState by

DllCall("kernell32.dll", "int", "GetCommState", "hwnd", $handle, "ptr", DllStructGetPtr($struct))

Link to comment
Share on other sites

if you use DLLStructCreate to reserve memory as you describe you can use DLLStructData as I mention.

Now you have to call the GetCommState by

DllCall("kernell32.dll", "int", "GetCommState", "hwnd", $handle, "ptr", DllStructGetPtr($struct))

That was a quick reply!

I have tested what you suggested. But with the same result.

I think you missunderstand what Iam trying to do.

It is not I that should set the values in the struct, I should get the values from the dll(call).

Even if I first uses:

DllStructSetData($DCB, 3, 1)

DllStructSetData($DCB, 4, 1)

...

It will be overwriten by the DLLcall (and I want to get the values from the dll).

The problem is that the dll "belive" that the first Dword is a Bit. After It has sent the bit it will continue to send the rest of the information (yet another bit/flag) in the same Dword. When it actually should send it to the next dword.

I have a bit difficult to make my self clear, but I hope you understand what I mean.

I appreciate the time you put in to this!!!

Link to comment
Share on other sites

For an example:

The dll sends back a number of "variables":

First

010010110000

Baudrate

Second

0 or 1

Flag called fBinary

Third

0 or 1

Flag called fparity

and so on

this means that both second and third (and more) variable will end up in the same dword.

Link to comment
Share on other sites

I don't know why GetCommstate return more than what is described if the specification but you need to keep only the bits defined 1 or 2 with a BitAnd :P

Again, thanks for your time an effort

Unfortunate I belive that your solution with BitAnd isn't working.

The problem isn't (as far as I can understand) that the DLL returns more than it should.

The problem is, that in VB you have the ability to define a DWord as a bit:

DWORD fBinary :1 <--- by using this

But in AutoIT that isn't possible. The problem would be very easy to solve if there was a "Bit" variable in AutoIT.

The solution with BitAnd will delete the information that should be in the other variabels

Link to comment
Share on other sites

Your solution gave me an idea (better late than never :P).

I store all the variables that should be only a bit in a byte (or short)

If I then uses BitAnd I should be possible to get only the one bit that I'am looking for.

By doing so for every bit in the byte I get 8 variabel that only contain a flag.

(then it repeats until all byte is checked)

Something like this:

$fParity = BitAND(DllStructGetData($DCB,3) ,1)

$fOutxCTSFlow = BitAND(DllStructGetData($DCB,3) ,2)

$fOutxDSRFlow = BitAND(DllStructGetData($DCB,3) ,4)

I only have to figure out exactly how BITAND works.

I will try it and post the result in this thread

Thanks again for your help

/andreas

Link to comment
Share on other sites

Your solution gave me an idea (better late than never :P).

I store all the variables that should be only a bit in a byte (or short)

If I then uses BitAnd I should be possible to get only the one bit that I'am looking for.

By doing so for every bit in the byte I get 8 variabel that only contain a flag.

(then it repeats until all byte is checked)

Something like this:

$fParity = BitAND(DllStructGetData($DCB,3) ,1)

$fOutxCTSFlow = BitAND(DllStructGetData($DCB,3) ,2)

$fOutxDSRFlow = BitAND(DllStructGetData($DCB,3) ,4)

I only have to figure out exactly how BITAND works.

I will try it and post the result in this thread

Thanks again for your help

/andreas

I check the DCB structure under C and I think the the file I include is the good way. fOutxCTSFlow is not in the second bit position as your bitAND isolate it neither fOutxDSRFlow in third.

What I don't really understand is whhy so many info in the fbinary when unmask?

Perhaps I don't really understand what this GetCommState is returning.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...