Converting System.Guid to _GUID  
Author Message

PostPosted: Visual C# Language, Converting System.Guid to _GUID Top


I have to convert a System.Guid variable to a _GUID but I don't know how.
The declaration of the function (in Microsoft.FlightSimulator.SimConnect):
public void ExecuteMissionAction(_GUID guidInstanceId);
The guid I have: {0110DB64-FED1-4E40-A134-4F755A8245D1}

And I have an other problem. I cannot use _GUID. I added ISymWrapper to the references, but when I want to build the project I get the following message: "error CS0122: '_GUID' is inaccessible due to its protection level"

So, how can I call ExecuteMissionAction with this guid


Visual C#12  
Peter Ritchie

PostPosted: Visual C# Language, Converting System.Guid to _GUID Top

What type is ExecuteMissionAction expecting, a string You can always use the Guid class's ToString() member to format the GUID as a string.


PostPosted: Visual C# Language, Converting System.Guid to _GUID Top

I tried Guid.ToString, but it didn't work. It sent me an error message while building the project: "error CS1503: Argument'1': cannot convert from 'string' to '_GUID'"

Also, I tried GuidConverter, which didn't work, too. GuidConverter needs a parameter of Object. I tried it, but it didn't work,too.

By the way, I'm a beginner in C#, I used to develop in Borland Delphi, so everything is new for me in C#. :-) But it is strange for me... Microsoft made an interface for developers to write their applications for FSX (Flight Simulator X), they released a SDK, but most of the examles are in C++... :-(

One more thing: I inlcuded the Simconnect .dll in my project. (using Microsoft.FlightSimulator.SimConnect;) I can use many variables and events which are described in the SDK, but I cannot use the ExecuteMissionExecute, because C# doesn't know te variable _GUID. (C++ knows it, I saw it in a sample...)

At least, sorry for my poor English, it is not my native language...



Peter Ritchie

PostPosted: Visual C# Language, Converting System.Guid to _GUID Top

It's hard to say. I don't know how they've defined _GUID. A managed application normally uses either System.Guid or it pinvokes a function and the CLR marshals the data for you. I can't find any information about the Flight Simulator SDK; so I can't know for sure how to go back and forth from Guid to _GUID.

You might try the Microsoft games simulators newsgroup: ;cat=en_US_f5c26c4c-9442-4038-ab1e-b3d34006e2de&lang=en&cr=US

While there's many Microsoft newsgroups in different languages, there are unfortunately no **** newsgroups in Hungarian.

James Curran

PostPosted: Visual C# Language, Converting System.Guid to _GUID Top

Now, as far as I can figure out, the _GUID is ISymWrapper and the _GUID in Microsoft.FlightSimulator.SimConnect are separate attempts to use the SDK struct GUID in managed code, and both define it as internal.

Nevertheless, the MSDN does give Managed C++ source code to covnert to/from a System.Guid.

So, with a little help from and some puttering around, we get:

[StructLayout(LayoutKind.Sequential, Size=0x10)]

struct _GUID
public Int32 Data1;
public Int16 Data2;
public Int16 Data3;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=
public byte[] Data4;

Guid FromGUID(_GUID guid)
return new Guid(guid.Data1, guid.Data2, guid.Data3,

_GUID ToGUID(Guid guid)
_GUID newGuid =
new _GUID();
byte[] guidData = guid.ToByteArray();
newGuid.Data1 = BitConverter.ToInt32(guidData,
newGuid.Data2 = BitConverter.ToInt16(guidData,
newGuid.Data3 = BitConverter.ToInt16(guidData,
newGuid.Data4 =
new byte[8];
8, newGuid.Data4, 0, 8);
return newGuid;