RS232 wrapper: GetCommConfig

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The WIN32 API function 'GetCommConfig' Can be used to retrieve the Configuration settings. It is defined as follows
structure COMMCONFIG
{
int dwSize;
short wVersion;
short wReserved;
DCB dcb;
int dwProviderSubType;
int dwProviderOffset;
int dwProviderSize;
char[] wcProviderData
}
My question concerns the 'wcProviderData' element. I'm aware that this element is not used when addressing an RS232 port, however I'm interested in which case a communication device (which is opened using 'CreateFile') does fill this parameter. Because in C# Marshalling is necessary to retrieve this structure, I would like a test situation where this field is actually filled by a device

Furthermore I'm wondering how the memory allocated for the ProviderData can be freed again, assuming it is allocated by the communications device
I could do this (only showing the relevant code)

COMMCONFIG cc
int iSize = cc.dwSize = Marshal.SizeOf ( m_CommConfig )
IntPtr ipCommConfig = Marshal.AllocHGlobal ( cc.dwSize )

int iResult = GetCommConfig ( iHandle, ipCommConfig, ref iSize )
Marshal.PtrToStructure ( ipCommCOnfig, cc )

cc.wcProviderData = new char[cc.dwProviderSize/2
IntPtr ipProvData = Marshal.ReadIntPtr ( ipCommConfig, cc.dwProviderOffset )
Marshal.PtrToStructure ( ipProvData, cc.wcProviderData )

But if the CommConfig Structure is collected by the GC is there no memory leak then

Could anyone please comment on the suggested code above and the questions posed in this posting
Thanks
Stefan.
 
Back
Top