Hi, everyone. I have this kind of problem.
On faculty i got to make an example of OPC HDA server with async reading.
Also, only thing i got is specification of OPC standards.
Now, i have trouble. I have OPC Core components exe file, which i instaled.
When i create my file which implement, let say, IOPCCommon interface, i imported required dll file,
which provide necessary interface.
For one of methods i got next thing.
public void GetErrorString(int dwError, out string ppString)
{
throw new Exception("The method or operation is not implemented.");
}
In specification is said that this method returns HResult
HRESULT GetErrorString(
[in] HRESULT dwError,
[out, string] LPWSTR *ppString
);
How should i implement this and symilar methods
Thanks in advance.

Which type in C# is equivalent to C++ HResult?
Anand77
I do not have .NET api, because i do not have right to download it, because it is too expensive for me to register.
Tryin2Bgood
victu
RAED KASSAWAT
Tnx everyone, i now have pretty big and clear picture what i must do.
I will change all my methods to HRESULT type, which will be as this:
using
System;using System.Collections.Generic;
using System.Text;
namespace OPCServer
{
class HRESULT
{
public static readonly int S_OK = 0;
public static readonly int S_FALSE = 1;
public static readonly int E_NOTIMPL = 2;
public static readonly int E_INVALIDARG = 3;
public static readonly int E_FAIL = 4;
}
}
This will represent return values of all my methods, which need HRESULT.
Steven Twitchell - MSFT
If by "but also, from OPC site, i downloaded OPC Core Components with dll files, which contain needed interfaces", you mean you downloaded the "OPC .Net API", then you should not use the IDL files as a reference - they are for the unmanaged (that is, not .net) interfaces.
The .Net API should have completely different documentation (hopefully), and will not use any non-.net types like HRESULT (so you won't have to try converting types)
arse
Hi,
System.IntPtr
cheers
akin_l
Wrong example from me, sorry.
My problem, in total, is how to implement OPC interfaces in C#. Yes, i have IDL files, but also, from OPC site, i downloaded OPC Core Components with dll files, which contain needed interfaces. Also, when i use some of dlls in project I can make this:
using System;
using System.Collections.Generic;
using System.Text;
using OpcRcw.Comn;
using System.Runtime;
namespace OPCServer
{
class OPCCommon : IOPCCommon
{
#region IOPCCommon Members
public void GetErrorString(int dwError, out string ppString)
{
throw new Exception("The method or operation is not implemented.");
}
public void GetLocaleID(out int pdwLcid)
{
throw new Exception("The method or operation is not implemented.");
}
public void QueryAvailableLocaleIDs(out int pdwCount, out IntPtr pdwLcid)
{
throw new Exception("The method or operation is not implemented.");
}
public void SetClientName(string szName)
{
throw new Exception("The method or operation is not implemented.");
}
public void SetLocaleID(int dwLcid)
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
}
}
(This is just one of interfaces IOPCCommon)
But, by IDL files, this interface looks like this:
interface IOPCCommon : IUnknown
{
HRESULT SetLocaleID (
[in] LCID dwLcid
);
HRESULT GetLocaleID (
[out] LCID *pdwLcid
);
HRESULT QueryAvailableLocaleIDs (
[out] DWORD *pdwCount,
[out, size_is(,*pdwCount)] LCID **pdwLcid
);
HRESULT GetErrorString(
[in] HRESULT dwError,
[out, string] LPWSTR *ppString
);
HRESULT SetClientName (
[in, string] LPCWSTR szName
);
}
How i can use HRESULT in C#, if that is possible Or, if I can not do that, how i must implement this OPC Common interface, so it can provide necessary functionality for OPC Clients
This is my question, in general.
pappascd
So, you wanna write a DLL that the OPC exe file will then consume and it requires you to export some functions (like the GetErrorString()).
If this assumption is correct, this is not possible using C# since it can only output assemblies (managed DLLs), which your OPC exe will not be able to consume. In order to solve your problem, you will have to use C++ and compile a native DLL.
If my assumption is wrong, could you please explain it more detailed