Converting System.Guid to _GUID  
Author Message
Itchycoo





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

Hi,


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


Thanks,
Endre


Visual C#15  
 
 
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.

 
 
Itchycoo





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...

Kinds,

Endre


 
 
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: http://www.hide-link.com/ ;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 www.pinvoke.net 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=
8)]
public byte[] Data4;
}

Guid FromGUID(_GUID guid)
{
return new Guid(guid.Data1, guid.Data2, guid.Data3,
guid.Data4[
0],guid.Data4[1],guid.Data4[2],
guid.Data4[
3],guid.Data4[4],guid.Data4[5],
guid.Data4[
6],guid.Data4[7]);
}

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