Click here to Skip to main content
15,878,809 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Interesting Application? Pin
Colin Angus Mackay5-Sep-04 5:03
Colin Angus Mackay5-Sep-04 5:03 
GeneralRe: Interesting Application? Pin
mathon5-Sep-04 5:49
mathon5-Sep-04 5:49 
GeneralRe: Interesting Application? Pin
Colin Angus Mackay5-Sep-04 13:06
Colin Angus Mackay5-Sep-04 13:06 
GeneralTraining Cards Pin
adonisv3-Sep-04 15:38
adonisv3-Sep-04 15:38 
GeneralDirectX SDK for C# Pin
hxxbin3-Sep-04 8:49
hxxbin3-Sep-04 8:49 
GeneralRe: DirectX SDK for C# Pin
Antti Keskinen6-Sep-04 11:10
Antti Keskinen6-Sep-04 11:10 
GeneralRe: DirectX SDK for C# Pin
Hadi Fakhreddine8-Sep-04 20:48
Hadi Fakhreddine8-Sep-04 20:48 
Questioncan not return com from c# Pin
umedkurd3-Sep-04 2:13
umedkurd3-Sep-04 2:13 
OPC defines two main components(COM) registered in opcserver category : OpcServer & OpcGroup. I have written two coresponing classes as follows that implement the required Interfaces as defined by OPC.
[Guid( "926EFA52-C020-4259-B879-203512901EAF" )]
[ProgId("FAHM OPC Server 1")]
[ComVisible( true )]
public class OpcServer: IOPCServer, IOPCCommon, IOPCItemProperties, IOPCBrowseServerAddressSpace
{}
[Guid( "075A7104-076F-481f-8CCF-11BA9AE375EB" )]
[ProgId("FAHM OPC Group 1")]
[ClassInterface(ClassInterfaceType.None)]
public class OpcGroup: IOPCItemMgt, IOPCAsyncIO2, IOPCSyncIO, IOPCGroupStateMgt
{}

I can in a not managed programming language such as delphi or c++ create an instance of them and call all methods of both of them and QueryInterface them to all implemented Interfaces and see they are working by showing just a messagebox for test.
The problem is that the IOPCServer Interface defines a method AddGroup as follows that returns an instance of OPCGroup and has following signature in c++ and c#:
c++:
virtual HRESULT STDMETHODCALLTYPE AddGroup(
/* [string][in] */ LPCWSTR szName,
/* [in] */ BOOL bActive,
/* [in] */ DWORD dwRequestedUpdateRate,
/* [in] */ OPCHANDLE hClientGroup,
/* [in][unique] */ LONG __RPC_FAR *pTimeBias,
/* [in][unique] */ FLOAT __RPC_FAR *pPercentDeadband,
/* [in] */ DWORD dwLCID,
/* [out] */ OPCHANDLE __RPC_FAR *phServerGroup,
/* [out] */ DWORD __RPC_FAR *pRevisedUpdateRate,
/* [in] */ REFIID riid,
/* [iid_is][out] */ LPUNKNOWN __RPC_FAR *ppUnk) = 0;
c# :
void AddGroup(
[In, MarshalAs(UnmanagedType.LPWStr)] string szName,
[In, MarshalAs(UnmanagedType.Bool)] bool bActive,
[In] int dwRequestedUpdateRate,
[In] int hClientGroup,
[In] ref int pTimeBias,
[In] ref float pPercentDeadband,
[In] int dwLCID,
[Out] out int phServerGroup,
[Out] out int pRevisedUpdateRate,
[In] ref Guid riid,
[Out, MarshalAs(UnmanagedType.IUnknown)] out object ppUnk);
When in the unmanged code call this method of IOPCServer, it seems to be ok, but the returned object in ppUnk that supposed to be a IOPCItemMgt fails to execute any of its methods and raises an memory exception. I tried following implementation for OPCSerevr.AddGroup but all of them have the same wrong result:
impl. 1:
Type typeofGroup = Type.GetTypeFromProgID( "FAHM OPC Group 1" );
if( typeofGroup == null )
throw new Exception("OPC Server Not Found");
object grp = Activator.CreateInstance( typeofGroup );
IntPtr pRes = IntPtr.Zero;
IntPtr pUnk = Marshal.GetIUnknownForObject(obj);
Marshal.QueryInterface(pUnk, ref riid, out pRes);
Marshal.Release(pUnk);
Marshal.Release(pUnk);
if (!pRes.Equals(IntPtr.Zero))
ppUnk = pRes;
else
Marshal.ThrowExceptionForHR(HResult.E_NOINTERFACE);
impl. 2:
object grp = new OpcGroup();
ppUnk = IntPtr.Zero;
ppUnk = Marshal.GetComInterfaceForObject(grp, typeof(IOPCItemMgt));
impl. 3:
object grp = new OpcGroup();
ppUnk = grp;
impl. 4:
object grp = new OpcGroup();
ppUnk = (IOPCItemMgt)grp;
And for each of mentioned lines in above implementaions I surrounded it with a try-catch block and showed messageboxes after each successfull or failed block, and it seems that none of them fails, but I don't know why the returned IOPCItemMgt is incorrect. Can anyone help me?
Special Regards
Umed Kurdistan
GeneralProgramatically determining IP addresses Pin
Olof Forshell2-Sep-04 12:19
Olof Forshell2-Sep-04 12:19 
GeneralRe: Programatically determining IP addresses Pin
Anonymous2-Sep-04 21:41
Anonymous2-Sep-04 21:41 
GeneralVC++6.0->VC++.NET Pin
jetournier2-Sep-04 3:15
jetournier2-Sep-04 3:15 
GeneralRe: VC++6.0->VC++.NET Pin
jetournier2-Sep-04 3:17
jetournier2-Sep-04 3:17 
GeneralRe: VC++6.0->VC++.NET Pin
Antti Keskinen6-Sep-04 11:24
Antti Keskinen6-Sep-04 11:24 
GeneralMultiple versions Pin
hatim_ali1-Sep-04 21:40
hatim_ali1-Sep-04 21:40 
GeneralPixelFormat of the Screen ( Desktop ) Pin
Michael Menne1-Sep-04 10:32
Michael Menne1-Sep-04 10:32 
Generalprogram terminates unexpectedly, with no message Pin
Anonymous31-Aug-04 23:49
Anonymous31-Aug-04 23:49 
GeneralRe: program terminates unexpectedly, with no message Pin
mav.northwind1-Sep-04 6:10
mav.northwind1-Sep-04 6:10 
QuestionHow To Save a Crystal Report- SaveAs() Pin
Ranoush31-Aug-04 22:00
Ranoush31-Aug-04 22:00 
AnswerRe: How To Save a Crystal Report- SaveAs() Pin
Steven Campbell1-Sep-04 8:15
Steven Campbell1-Sep-04 8:15 
GeneralCreate XML Document Pin
Pokemon_G31-Aug-04 19:53
Pokemon_G31-Aug-04 19:53 
GeneralRe: Create XML Document Pin
Steven Campbell1-Sep-04 8:16
Steven Campbell1-Sep-04 8:16 
GeneralRe: Create XML Document Pin
DavidNohejl29-Sep-04 12:15
DavidNohejl29-Sep-04 12:15 
QuestionPull data from external file? Pin
Glisson30-Aug-04 12:22
Glisson30-Aug-04 12:22 
GeneralGDI+ question: image jitter when resizing Pin
DivideByNought30-Aug-04 10:29
DivideByNought30-Aug-04 10:29 
GeneralRe: GDI+ question: image jitter when resizing Pin
DivideByNought1-Sep-04 7:59
DivideByNought1-Sep-04 7:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.