Ok, Here is the relevant code.
The method at hand is
USDALib.PhysicalLocation_t[] GetROI(int partID, string roiName);
The USDALib is the USDALib.dll interop for the COM object USDA.dll
The VB6 code is referencing the USDA.ll (the native COM object) that
defines
the PhysicalLocation_t
and also referencing the 1000 Gates
///////////////////////////////////
/// File 1000GatesInterface.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MultiBScanDisplay
{
[ComVisible(true),
Guid(GUIDs.IID_I1000Gates),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface I1000Gates
{
// The USDALib is the USDALib.dll interop for the COM object USDA.dll
USDALib.PhysicalLocation_t[] GetROI(int partID, string roiName);
}
}
///////////////////////////////////
/// File COMBridge.cs
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace MultiBScanDisplay
{
/// <summary>COMBridgeFor1000Gates is the bridge between the
application
/// interfaces and the actual implementation of the methods.</summary>
[Guid(GUIDs.CLASS_1000Gates)]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("MultiBScan.1000Gates")]
[ComVisible(true)]
public class COMBridgeFor1000Gates : ReferenceCountedObjectBase,
I1000Gates
{
public static EvaluationForm m_evalForm;
[DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int _controlfp(int n, int mask);
[DllImport("kernel32.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern bool IsWow64Process(IntPtr hProcess, out bool
Wow64Process);
[DllImport("kernel32.dll", CharSet=CharSet.Ansi, ExactSpelling=true)]
public static extern UIntPtr GetProcAddress(IntPtr hModule, string
procName);
public COMBridgeFor1000Gates()
{
// README: according to Microsoft knowledge base!
UIntPtr pIsWow64Process = UIntPtr.Zero;
bool Is64 = false;
// Query for IsWow64Process function, if doesn't exist then not a 64bit
system.
pIsWow64Process =
GetProcAddress(System.Diagnostics.Process.GetCurrentProcess().Handle,"IsWow64Process");
if( pIsWow64Process != UIntPtr.Zero )
{
// Function exists, check it for values.
IsWow64Process(System.Diagnostics.Process.GetCurrentProcess().Handle,out
Is64);
}
// Perform if not a 64bit system.
if( !Is64 )
{ // this flag should be set in 32bit system in order to
avoid
an exception in the drawing.
_controlfp(0x9001F, 0xFFFFF);
}
}
~COMBridgeFor1000Gates()
{
m_evalForm.Close();
}
#region I1000Gates Members
USDALib.PhysicalLocation_t[] I1000Gates.GetROI(int partID, string
roiName)
{
return new USDALib.PhysicalLocation_t[0];
USDALib.PhysicalLocation_t[] jp = new
USDALib.PhysicalLocation_t[10];
for( int i=0; i < 10; ++i )
{
jp
.Pixel = i;
jp.ScanLine = i;
jp.Value = i;
}
return jp;
}
#endregion I1000Gates Members
}
#region Factory Class for COM object
class BridgeClassFactoryFor1000Gates : ClassFactoryBase
{
public override void virtual_CreateInstance(IntPtr pUnkOuter, ref Guid
riid, out IntPtr ppvObject)
{
if( riid == Marshal.GenerateGuidForType(typeof(I1000Gates)) ||
riid == Program.IID_IDispatch ||
riid == Program.IID_IUnknown )
{
COMBridgeFor1000Gates COMBridge_New = new COMBridgeFor1000Gates();
ppvObject = Marshal.GetComInterfaceForObject(COMBridge_New,
typeof(I1000Gates));
EvaluationConfiguration.ExecutionMode =
EvaluationConfiguration.RunMode.ActiveX;
}
else
{
throw new COMException("No interface", unchecked((int) 0x80004002));
}
}
}
#endregion Factory Class for COM object
}
//////////////////////////////////////////
//// File IClassFactory.cs
using System;
using System.Runtime.InteropServices;
namespace MultiBScanDisplay
{
///<summary>
/// Interface IClassFactory is here to provide a C#
/// definition of the COM IClassFactory interface.
///</summary>
[ComImport, // This interface originated from COM.
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),// Indicate that this
interface is not IDispatch-based.
Guid("00000001-0000-0000-C000-000000000046")]// This GUID is the
actual
GUID of IClassFactory.
public interface IClassFactory
{
/// <summary>CreateInstance.</summary>
/// <param name="pUnkOuter">Unknown outer.</param>
/// <param name="riid">RI ID.</param>
/// <param name="ppvObject">PPV Object.</param>
void CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr
ppvObject);
/// <param name="fLock">Lock flag.</param>
void LockServer(bool fLock);
}
}
//////////////////////////////////////////
//// File GUIDs.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MultiBScanDisplay
{
public class GUIDs
{
internal const string CLASS_1000Gates =
"1B4363BF-33DF-49c7-B0D0-A201E631C100";
internal const string IID_I1000Gates =
"BE8E6044-5B18-4d56-AA75-9E5120F27884";
}
}
//////////////////////////////////////////////////////
--
Thanks
Sharon
--
Thanks
Sharon
Willy Denoyette said:
Sharon said:
My Client is VB Visual Studio 6 and I have a reference to COM Interface
from
C# application.
The method signature is (viewed by the OLE View):
[id(0x60020001)]
HRESULT GetROI(
[in] long partID,
[in] BSTR roiName,
[out, retval] SAFEARRAY(PhysicalLocation_t)* pRetVal);
I'm trying to call GetROI and I'm getting exeption with "Element not
found"
message.
The code in VB looks like that:
Dim PhLocationPoints() As PhysicalLocation_t
Dim Iface as TheCOClass
Set Iface = new TheCOClass
If Not Iface Is Nothing Then
PhLocationPoints = Iface.GetROI(119, "ROI 3")
end if
Hard to tell without seeing any C# code, are you sure you are returning a
valid array when passed (119,"ROI 3")?
Willy.