Jump to content
The simFlight Network Forums

Aircraft Name - offset for aircraft type string? (VB6)


Recommended Posts

Guest Garen
Posted

I've had alot of success with querying FSUIPC for things like latitude, altitude, etc - but this one has me stumped.

I'm trying to query FSUIPC for the currently loaded aircraft. As described in _FSUIPC For Programmers_ this can be accomplished with a 24 byte read at offset 3160. The code copiles fine, but when run it terminates the program and then I get an error dialog from Windows: "Your program has generated errors and will be closed by Windows"

I'm using VB6, FSUIPC.DLL 2.95, W2000Pro, FS2002Pro. Code follows - any help appreciated - this is not for a commercial project:

'Query FSUIPC for the currently loaded user aircraft

Dim dwResult as Long

Dim dwString as string

FSUIPC_Initialization

If FSUIPC_Open(SIM_ANY, dwResult) Then

If FSUIPC_Read(&H3160, 24, VarPtr(dwString), dwResult) Then

If FSUIPC_Process(dwResult) Then

'Display the string in a message box

MsgBox (dwString)

End If

End If

FSUIPC_Close

EndIf

=

Thanks,

Garen

Guest Garen
Posted

I've had alot of success with querying FSUIPC for things like latitude, altitude, etc - but this one has me stumped.

I'm trying to query FSUIPC for the currently loaded aircraft. As described in _FSUIPC For Programmers_ this can be accomplished with a 24 byte read at offset 3160. The code copiles fine, but when run it terminates the program and then I get an error dialog from Windows: "Your program has generated errors and will be closed by Windows"

I'm using VB6, FSUIPC.DLL 2.95, W2000Pro, FS2002Pro. Code follows - any help appreciated - this is not for a commercial project:

'Query FSUIPC for the currently loaded user aircraft

Dim dwResult as Long

Dim dwString as string

FSUIPC_Initialization

If FSUIPC_Open(SIM_ANY, dwResult) Then

If FSUIPC_Read(&H3160, 24, VarPtr(dwString), dwResult) Then

If FSUIPC_Process(dwResult) Then

'Display the string in a message box

MsgBox (dwString)

End If

End If

FSUIPC_Close

EndIf

=

Thanks,

Garen

Guest hsors
Posted

FSUIPC provides several "0 terminated strings" that require special coding techniques in VB..the one you used will raise an error since you tried to directly assign the 24 bytes to a string variable

Here is the modified code that will do the job

Dim dwResult as Long

Dim dwString as string

Dim b(23) as byte 'defined a byte array (24 values)

Dim result as string 'will contain the final string

Dim i as integer

FSUIPC_Initialization

If FSUIPC_Open(SIM_ANY, dwResult) Then

If FSUIPC_Read (&H3160,24,VarPtr (b(0)), dwResult) Then 'read all bytes at offset &H3160 in byte array

If FSUIPC_Process(dwResult) Then

For i=0 to 255

If b(i)=0 then exit for 'leave at 0 terminator

result=result+Chr(b(i)) 'otherwise adds to result (don't forget the Chr)

Next

End If

End If

FSUIPC_Close

EndIf

Hope it will helps

Hervé

Guest hsors
Posted

FSUIPC provides several "0 terminated strings" that require special coding techniques in VB..the one you used will raise an error since you tried to directly assign the 24 bytes to a string variable

Here is the modified code that will do the job

Dim dwResult as Long

Dim dwString as string

Dim b(23) as byte 'defined a byte array (24 values)

Dim result as string 'will contain the final string

Dim i as integer

FSUIPC_Initialization

If FSUIPC_Open(SIM_ANY, dwResult) Then

If FSUIPC_Read (&H3160,24,VarPtr (b(0)), dwResult) Then 'read all bytes at offset &H3160 in byte array

If FSUIPC_Process(dwResult) Then

For i=0 to 255

If b(i)=0 then exit for 'leave at 0 terminator

result=result+Chr(b(i)) 'otherwise adds to result (don't forget the Chr)

Next

End If

End If

FSUIPC_Close

EndIf

Hope it will helps

Hervé

Posted
I'm trying to query FSUIPC for the currently loaded aircraft. As described in _FSUIPC For Programmers_ this can be accomplished with a 24 byte read at offset 3160. The code copiles fine, but when run it terminates the program and then I get an error dialog from Windows: "Your program has generated errors and will be closed by Windows"

All VB programmers seem to have great problems with strings. It seems this is a big flaw in the language. I don't know VB so I hope someone else will jump in tyo help, but as a last resort have you considered treating the string as a 24 byte array instead? Can VB handle arrays? Then each ASCII character will occupy one element each in that array.

Doesn't VB come with a debugger? If so you should surely be able to trace through your code and find your error -- the usual problem I'm told is trying to pass strings "by value" instead of by pointer.

I note you have this:

Dim dwString as string

How does the VB compiler know to reserve 24 bytes for this string? Don't you have to tell it someplace? If you read 24 bytes into a space where it only allows for one, you will most certainly get errors.

Pete

Posted
I'm trying to query FSUIPC for the currently loaded aircraft. As described in _FSUIPC For Programmers_ this can be accomplished with a 24 byte read at offset 3160. The code copiles fine, but when run it terminates the program and then I get an error dialog from Windows: "Your program has generated errors and will be closed by Windows"

All VB programmers seem to have great problems with strings. It seems this is a big flaw in the language. I don't know VB so I hope someone else will jump in tyo help, but as a last resort have you considered treating the string as a 24 byte array instead? Can VB handle arrays? Then each ASCII character will occupy one element each in that array.

Doesn't VB come with a debugger? If so you should surely be able to trace through your code and find your error -- the usual problem I'm told is trying to pass strings "by value" instead of by pointer.

I note you have this:

Dim dwString as string

How does the VB compiler know to reserve 24 bytes for this string? Don't you have to tell it someplace? If you read 24 bytes into a space where it only allows for one, you will most certainly get errors.

Pete

Guest Garen
Posted

Hervé - thanks - that did the trick.

Pete is right about VB strings. I can do just about anything with strings and pointers in C, but VB6 is another animal. I'm still trying to figure out the difference between StrPtr and VarPtr in VB6...if it was C, then it'd just be a pointer and end of the story:) Even so, VB6 is really pretty nice to work with. Still, Dim'ing a variable as string gets you I dunno what kind of storage - I suppose it is somewhat dynamically determined.

Thanks again,

Garen

FSUIPC provides several "0 terminated strings" that require special coding techniques in VB..the one you used will raise an error since you tried to directly assign the 24 bytes to a string variable

Here is the modified code that will do the job

Dim dwResult as Long

Dim dwString as string

Dim b(23) as byte 'defined a byte array (24 values)

Dim result as string 'will contain the final string

Dim i as integer

FSUIPC_Initialization

If FSUIPC_Open(SIM_ANY, dwResult) Then

If FSUIPC_Read (&H3160,24,VarPtr (b(0)), dwResult) Then 'read all bytes at offset &H3160 in byte array

If FSUIPC_Process(dwResult) Then

For i=0 to 255

If b(i)=0 then exit for 'leave at 0 terminator

result=result+Chr(b(i)) 'otherwise adds to result (don't forget the Chr)

Next

End If

End If

FSUIPC_Close

EndIf

Hope it will helps

Hervé

Guest Garen
Posted

Hervé - thanks - that did the trick.

Pete is right about VB strings. I can do just about anything with strings and pointers in C, but VB6 is another animal. I'm still trying to figure out the difference between StrPtr and VarPtr in VB6...if it was C, then it'd just be a pointer and end of the story:) Even so, VB6 is really pretty nice to work with. Still, Dim'ing a variable as string gets you I dunno what kind of storage - I suppose it is somewhat dynamically determined.

Thanks again,

Garen

FSUIPC provides several "0 terminated strings" that require special coding techniques in VB..the one you used will raise an error since you tried to directly assign the 24 bytes to a string variable

Here is the modified code that will do the job

Dim dwResult as Long

Dim dwString as string

Dim b(23) as byte 'defined a byte array (24 values)

Dim result as string 'will contain the final string

Dim i as integer

FSUIPC_Initialization

If FSUIPC_Open(SIM_ANY, dwResult) Then

If FSUIPC_Read (&H3160,24,VarPtr (b(0)), dwResult) Then 'read all bytes at offset &H3160 in byte array

If FSUIPC_Process(dwResult) Then

For i=0 to 255

If b(i)=0 then exit for 'leave at 0 terminator

result=result+Chr(b(i)) 'otherwise adds to result (don't forget the Chr)

Next

End If

End If

FSUIPC_Close

EndIf

Hope it will helps

Hervé

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.