I should also note that the C++ project compiles to a DLL, which is then used by a parent C# DLL which connects to the SpacePilot Pro using HID. This C# DLL is then referenced by the application layer.
Any help would be appreciated.
Code: Select all
LogitechLCD_Applet::LogitechLCD_Applet(System::String^ AppletName, bool AutoStart, AppletCapabilities Capabilities, bool Configurable)
{
DWORD res=ERROR_SUCCESS; //assume success (also set if refCount>0)
void* tPntr;
if(LogitechLCD_Applet::refCount==0)
{
res = lgLcdInit();
}
if(ERROR_SUCCESS == res)
{
//keep the context around
myCTX=new lgLcdConnectContextEx();
memset(myCTX, 0, sizeof(lgLcdConnectContextEx));
tPntr=Marshal::StringToHGlobalUni(AppletName).ToPointer();
myCTX->appFriendlyName=(LPCWSTR)tPntr;
myCTX->dwAppletCapabilitiesSupported=(DWORD)Capabilities;
myCTX->isAutostartable=AutoStart;
myCTX->isPersistent=TRUE;
System::Delegate^ d;
if(Configurable)
{
//setup configuration callback hooks
myCTX->onConfigure.configContext=0; //no need for context, we are going to raise an event into the context space
//create a function delegate pointing back to this instance
d=gcnew PaR::LogitechLCD_Applet::dlgt_OnConfigCB(this,&PaR::LogitechLCD_Applet::OnConfigCB);
this->gcConfig=GCHandle::Alloc(d); //lock this in place since this delegate disapears once the method exits
myCTX->onConfigure.configCallback=(lgLcdOnConfigureCB)Marshal::GetFunctionPointerForDelegate(d).ToPointer();
}
//setup notification callback hooks
myCTX->onNotify.notifyContext=0; //no need for context, we are going to raise an event into the context space
//create a function delegate pointing back to this instance
d=gcnew PaR::LogitechLCD_Applet::dlgt_OnNotifyCB(this,&PaR::LogitechLCD_Applet::OnNotificationCB);
this->gcNotify=GCHandle::Alloc(d); //lock this in place since this delegate disapears once the method exits
myCTX->onNotify.notificationCallback=(lgLcdOnNotificationCB)Marshal::GetFunctionPointerForDelegate(d).ToPointer();
this->openCTX=new lgLcdOpenByTypeContext();
memset(openCTX,0,sizeof(lgLcdOpenByTypeContext));
//setup button callback hooks
openCTX->onSoftbuttonsChanged.softbuttonsChangedContext=this->openCTX;
d=gcnew PaR::LogitechLCD_Applet::dlgt_OnSoftButtonCB(this,&PaR::LogitechLCD_Applet::OnSoftButtonCB);
this->gcSoftButton=GCHandle::Alloc(d);
openCTX->onSoftbuttonsChanged.softbuttonsChangedCallback=(lgLcdOnSoftButtonsCB)Marshal::GetFunctionPointerForDelegate(d).ToPointer();
res=lgLcdConnectEx(myCTX);
if(res != ERROR_SUCCESS)
{
this->!LogitechLCD_Applet(); //free up my memory
throw res;
}
else
{
//attempt to open a connection to a device
openCTX->connection=myCTX->connection;
openCTX->device=LGLCD_INVALID_DEVICE;
openCTX->deviceType=(int)myCTX->dwAppletCapabilitiesSupported;
//try to open the context
DWORD res=lgLcdOpenByType(openCTX);
lgLcdSetAsLCDForegroundApp(openCTX->device,LGLCD_LCD_FOREGROUND_APP_NO);
LogitechLCD_Applet::refCount++; //bump the ref count
}
}
}
