ExternalSim CallBack problem

For topics related to the creation of simulation objects (SimObjects). This includes development of aircraft, ground, and maritime vehicles.
Locked
Ufeseros
Posts: 3
Joined: Thu Apr 24, 2014 12:48 pm

Post by Ufeseros »

Hello



here is my problem :

I have a dll that work fine in the v1.2 of prepar3D but not in the v2.2

it seem to be that the callback function is called only once in the v2

Do you have any ideas where it could come from ?



thank you
minime
Posts: 1198
Joined: Mon Jun 10, 2013 4:33 pm

Post by minime »

Can you extract the relevant source code and post it here?



Also, in your debugger you can see when your DLL is loaded and unloaded.... can you check if it is still loaded when the callback is not being called?



Ufeseros
Posts: 3
Joined: Thu Apr 24, 2014 12:48 pm

Post by Ufeseros »

I cant post the real code but, here a example witch had the same problem.



Code:
// test_dll_prepar3Dv2.cpp : définit les fonctions exportées pour l'application DLL.
//

#include "stdafx.h"
#include "stdio.h"
#include "globals.h"




#define EXTERNAL_SIM_CALLBACK_MASK (SIMCONNECT_EXTERNAL_SIM_CALLBACK_FLAG_CREATE | SIMCONNECT_EXTERNAL_SIM_CALLBACK_FLAG_DESTROY | SIMCONNECT_EXTERNAL_SIM_CALLBACK_FLAG_SIMULATE | SIMCONNECT_EXTERNAL_SIM_CALLBACK_FLAG_LOCATION_CHANGED | SIMCONNECT_EXTERNAL_SIM_CALLBACK_FLAG_EVENT)



void OnRecvExternalSimCreate(SIMCONNECT_RECV_EXTERNAL_SIM_CREATE *pCreate)
{
printf("***CREATE*** \n" );
SimConnect_SynchronousUnblock(g_hSimConnect);
}


void OnRecvExternalSimDestroy(SIMCONNECT_RECV_EXTERNAL_SIM_DESTROY *pDestroy)
{
printf("***DESTROY*** \n" );
SimConnect_SynchronousUnblock(g_hSimConnect);
}


void OnRecvExternalSimSimulate(SIMCONNECT_RECV_EXTERNAL_SIM_SIMULATE *pSimulate)
{

printf("***SIMULATE*** \n" ) ;
SimConnect_SynchronousUnblock(g_hSimConnect);
}


void OnRecvExternalSimLocationChanged(SIMCONNECT_RECV_EXTERNAL_SIM_LOCATION_CHANGED *pLocationChanged)
{
printf("***LOCATION CHANGED*** \n" );
SimConnect_SynchronousUnblock(g_hSimConnect);
}


void OnRecvExternalSimEvent(SIMCONNECT_RECV_EXTERNAL_SIM_EVENT *pEvent)
{

printf("***EVENT*** \n" ) ;
SimConnect_SynchronousUnblock(g_hSimConnect);
}

void OnRecvException(SIMCONNECT_RECV_EXCEPTION *pExceptionData)
{
}


void OnRecvQuit()
{
printf("***QUIT*** \n" ) ;
SimConnect_UnregisterExternalSim(g_hSimConnect, g_guidExternalSim);
}

void OnRecvOpen(SIMCONNECT_RECV_OPEN *pOpenData)
{
printf("***OPEN*** \n" ) ;
//this is used for the weather setting : just give a METAR and P3D interpret it
SimConnect_WeatherSetObservation(g_hSimConnect, 30, "GLOB 9999");

// register as an external sim client
SimConnect_RegisterExternalSim(g_hSimConnect, g_guidExternalSim, EXTERNAL_SIM_CALLBACK_MASK, PER_VEHICLE_SIMULATE_DEFINITION);
}



void CALLBACK SimConnectProcess(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext)
{

printf("***RUNNING*** \n" ) ;
// process SIMCONNECT_RECV_ID_XXX values here as needed

printf(" case " ) ;
switch(pData->dwID)
{
case SIMCONNECT_RECV_ID_EXTERNAL_SIM_CREATE:
{
printf("1 \n " ) ;
//callback of the creation of our simulated vehicle
OnRecvExternalSimCreate((SIMCONNECT_RECV_EXTERNAL_SIM_CREATE*)pData);
}
break;

case SIMCONNECT_RECV_ID_EXTERNAL_SIM_DESTROY:
{
printf("2 \n " ) ;
//callback used as a destructor
OnRecvExternalSimDestroy((SIMCONNECT_RECV_EXTERNAL_SIM_DESTROY*)pData);
}
break;

case SIMCONNECT_RECV_ID_EXTERNAL_SIM_SIMULATE:
{
printf("3 \n " ) ;
//callback called each P3D cycle
OnRecvExternalSimSimulate((SIMCONNECT_RECV_EXTERNAL_SIM_SIMULATE*)pData);
}
break;

case SIMCONNECT_RECV_ID_EXTERNAL_SIM_LOCATION_CHANGED:
{
printf("4 \n " ) ;
OnRecvExternalSimLocationChanged((SIMCONNECT_RECV_EXTERNAL_SIM_LOCATION_CHANGED*)pData);
}
break;

case SIMCONNECT_RECV_ID_EXTERNAL_SIM_EVENT:
{
printf("5 \n " ) ;
OnRecvExternalSimEvent((SIMCONNECT_RECV_EXTERNAL_SIM_EVENT*)pData);
}
break;

case SIMCONNECT_RECV_ID_EXCEPTION:
{
printf("6 \n " ) ;
OnRecvException((SIMCONNECT_RECV_EXCEPTION*)pData);
}
break;

case SIMCONNECT_RECV_ID_QUIT:
{
printf("7 \n " ) ;
OnRecvQuit();
}
break;

case SIMCONNECT_RECV_ID_OPEN:
{
printf("8 \n " ) ;
OnRecvOpen((SIMCONNECT_RECV_OPEN*)pData);
}
break;

default:
{
printf("default \n " ) ;
}

}

}

void __stdcall DLLStart( void )
{

AllocConsole() ;
AttachConsole( GetCurrentProcessId() ) ;
freopen( "CON", "w", stdout ) ;

HRESULT hr;



printf("***Tentative de Connexion au serveur local prepar3D*** \n" ) ;

// open connection to local SimConnect server
if ( SUCCEEDED(SimConnect_Open(&g_hSimConnect, ("ExternalSim"), NULL, 0, NULL, SIMCONNECT_OPEN_CONFIGINDEX_LOCAL)) && g_hSimConnect != NULL)
{

printf("***Connexion reussie*** \n" );

//register callback routine for message processing
hr = SimConnect_CallDispatch(g_hSimConnect, SimConnectProcess, NULL);


}
}

void __stdcall DLLStop( void )
{
printf("\n sortie dll \n");
if (g_hSimConnect != NULL)
{
SimConnect_Close(g_hSimConnect);
g_hSimConnect = NULL;
}
g_VehicleList.clear();
}



there is the console output on prepar3D 1 :







and on prepar 2:







also i can't check with the debugger, Prepar3D and visual studio are not on the same computer.







Ufeseros
Posts: 3
Joined: Thu Apr 24, 2014 12:48 pm

Post by Ufeseros »

i forgot to said :



on the first console i take the screenshot before the "simulation" start , but when its start i have the "**SIMULATE**" output



But the prepar3Dv2 console stay like this, but if i close prepar3Dv2 i have the output "sortie" called in the DLLstop
Locked