Hi all...
I'll try my best to keep this query as compact as possible...
I'm currently working on a project that involves generating alarms/notifications for the Automated Distributed Control System at the company. Well, for this, the team has created Notification Client and Notification Server Applications.
There is also another .exe created that dumps a message (the message is taken from a database, by means of a function) into a Private queue (which can be viewed in the Computer Management tool). This .exe is intended to run alongside the Notification Server Application, which accesses the queue to obtain the messages, which are then displayed at the User Station by means of a method created (called rhsc_notifications; I'll detail that later).
The problem we are facing is that the display at the User station is truncated, i.e. in all fields, only the first character is displayed, and remaining data is missing. (The alarm/notification is displayed as multiple fields like Alarm generation location, priority, description, time, etc.).
This problem is faced when the Notification Server uses a method called rhsc_notifications directly. However, one of the team members created an interface in Visual Basic. This interface is called by the Notification Server, and the interface processes the message, and calls the rhsc_notifications method to display the message at the User Station. When this interface is used, the display turns out fine, no truncation. However, when the rhsc_notifications method is called directly from the Notification Server Application, there is truncation.
We are required to eliminate this interface, and call rhsc_notifications method directly. The thing is that this method uses a library that has NOT been developed in a .Net environment. Hence, there is the need to marshal the data.
We've tried a few things with marshaling, but the problem hasn't been resolved. So I'm hoping you guys will be able to help me out with this...
The rhsc_notifications method is as follows:
int rhsc_notifications (char *szhostname
int cjrnd
NOTIFICATION_DATA* notd);
Here, szhostname is the server host name;
notd is a pointer to an array of NOTIFICATION_DATA structures (one array element for each request);
cprmbd is the number of notifications requested.
The structure of the NOTIFICATION_DATA structure (which is defined in another header file), is as follows:
*************************************************************
struct timeb timebuf
n_long nPriority
n_long nSubPriority
n_char* szName
n_char* szEvent
n_char* szAction
n_char* szLevel
n_char* szDescription
n_char* szUnits
n_char* szValue
n_long fstatus (This is actually unused, they must've put it in for
future usage)
*************************************************************
The part of the code where marshaling has been attempted is as follows:
*****************************************************************
class MessageProcessor
{
private DBInitialize m_oConfigurationEngine;
static EventLog eventlogging;
private static double m_sDBInitializeTimeStamp;
//[MarshalAs(UnmanagedType.LPStr)]
internal static string epksHost;
////////////////// Attempts at Marshaling////////////////////////////////
////[StructLayout(LayoutKind.Sequential,CharSet = CharSet.Ansi)]
//public struct timeb
//{
// //[MarshalAs(UnmanagedType.I8)]
// public Int64 t_time;
// //[MarshalAs(UnmanagedType.U2)]
// public ushort millitime;
// //[MarshalAs(UnmanagedType.I2)]
// public Int16 timezone;
// //[MarshalAs(UnmanagedType.I2)]
// public Int16 dstflag;
// //[MarshalAs(UnmanagedType.I8)]
// //public long test;
// //[MarshalAs(UnmanagedType.I8)]
// //public long time;
//}
////[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
//public struct Notification_Data
//{
// //[MarshalAs(UnmanagedType.Struct)]
// public timeb buftime;
// // [MarshalAs(UnmanagedType.I8)]
// public long nPriority;
// // [MarshalAs(UnmanagedType.I8)]
// public long nSubPriority;
// // [MarshalAs(UnmanagedType.LPStr,SizeConst = 20 )]
// public string szName;
// //[MarshalAs(UnmanagedType.LPStr, SizeConst = 20)]
// public string szEvent;
// //[MarshalAs(UnmanagedType.LPStr, SizeConst = 20)]
// public string szAction;
// //[MarshalAs(UnmanagedType.LPStr, SizeConst = 20)]
// public string szLevel;
// //[MarshalAs(UnmanagedType.LPStr, SizeConst = 50)]
// public string szDesc;
// //[MarshalAs(UnmanagedType.LPStr, SizeConst = 20)]
// public string szValue;
// //[MarshalAs(UnmanagedType.LPStr, SizeConst = 20)]
// public string szUnits;
// //[MarshalAs(UnmanagedType.I8)]
// public long fstatus;
//}
////[MarshalAs(UnmanagedType.LPStr)]
//internal Notification_Data[] NotifyData = new Notification_Data[1];
//[DllImport("hscnetapi.dll", EntryPoint = "rhsc_notifications", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
//public static extern int rhsc_notifications([In] [MarshalAs(UnmanagedType.LPStr)] string epksHostName, [In] [MarshalAs(UnmanagedType.I4)] int cjrnd, [In, Out] ref Notification_Data Notify_data);
*****************************************************************
(It's been commented because we're bypassing this part and are using the interface now...).
Do let me know if any further information is required (there's more code, I dunno if I need to display any more, or if this is sufficient...).
Thanks in advance :),
Tunçay