My ocx file is KisPosAgent.ocx. Registry added with regsvr32 ./KisPosAgent.cox. (x86)
I'm trying to invoke ocx methods in C++ (or C#).
I tried three different approaches:
1. C++, CoCreateInstance
#include <stdio.h>
#include <windows.h>
#include <objbase.h>
// This is my ocx (Run cl and tlh, til created)
#import "./KisPosAgent.ocx" named_guids no_namespace
int main(void)
{
CoInitialize(NULL);
_DKisPosAgent* pUnknown = NULL;
HRESULT hr = CoCreateInstance(__uuidof(KisPosAgent), NULL, CLSCTX_INPROC, __uuidof(_DKisPosAgent), (void**)&pUnknown);
// ERROR: _com_error 0x7763B5B2
short result = pUnknown->Init();
return 0;
}
2. C#, Just referenced
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace KisPosAgentBridge
{
class Program
{
static void Main(string[] args)
{
// Refernece ocx file (and auto-generated Interop.KisPosAgentLib)
var kis = new KisPosAgentLib.KisPosAgent();
// ERROR: HRESULT: 0x8000FFFF (E_UNEXPECTED)
kis.Init();
}
}
}
3. C#, Windows Forms
// Form1.Designer.cs
// Reference ocx file
private AxKisPosAgentLib.AxKisPosAgent axKisPosAgent1;
// Form1.cs
this.axKisPosAgent1.Init(); // Worked!
First and second didn't work: When the method is invoked, I get errors. But, the third works well.
What's the difference between first/second and third?
- Does activex(ocx) work on a UI-provided environment (such as windows forms)?
- Is the error caught because
IsInvokeAllowedis not provided? (https://github.com/idobatter/node-win32ole/issues/23)