How to add direct support for jBridge in your host (For developers only)

The following code example shows how to add support for jBridge in your host.

Basically, the implementation can consist of invoking the LoadBridgedPlugin(path) call if the normal loading routine fails, due to a different architecture. After that, it will work like any other native plugin.

//##########################################################################//

// Name of the proxy DLL to load
#define PROXY_REGKEY        “Software\\JBridge”

#ifdef _M_X64
#define PROXY_REGVAL        “Proxy64”  //use this for x64 builds
#else
#define PROXY_REGVAL        “Proxy32”  //use this for x86 builds
#endif

// Typedefs to save having to bring in the VST SDK
// (we don’t actually use any of these)

typedef void * audioMasterCallback;
struct AEffect;

// Typedef for BridgeMain proc
typedef AEffect * (*PFNBRIDGEMAIN)( audioMasterCallback audiomaster, char * pszPluginPath );

//Check if it’s a plugin_name.xx.dll
bool IsBootStrapDll(char * path)
{
bool ret = false;

HMODULE hModule = LoadLibrary(path);
if( !hModule )
{
//some error…
return ret;
}

//Exported dummy function to identify this as a bootstrap dll.
if( GetProcAddress(hModule, “JBridgeBootstrap”) )
{
//it’s a bootstrap dll
ret = true;
}

FreeLibrary( hModule );

return ret;
}

//*******************************

//receives the plugin’s path as an argument

AEffect * LoadBridgedPlugin(char * szPath)
{

/*optional, but recommended
please note that this will cause the bootstrap dlls (plugin_name.xx.dll) to be ignored,
which may not be desirable if your host relies on the plugin’s location rather than its ID*/
if( IsBootStrapDll( szPath ) )
{
MessageBox(GetActiveWindow(), “This is a bootstrap dll. Therefore, it will be ignored.”, “Warning”, MB_OK|MB_ICONHAND);
return 0;
}

// Get path to JBridge proxy
CHAR szProxyPath[MAX_PATH];
szProxyPath[0]=0 ;
HKEY hKey;
if ( RegOpenKey(HKEY_LOCAL_MACHINE, PROXY_REGKEY, &hKey) == ERROR_SUCCESS )
{
DWORD dw=sizeof(szProxyPath);
RegQueryValueEx(hKey, PROXY_REGVAL, NULL, NULL, (LPBYTE)szProxyPath, &dw);
RegCloseKey(hKey);
}

// Check key found and file exists
if ( szProxyPath[0]==0 )
{
MessageBox(GetActiveWindow(), “Unable to locate proxy DLL”, “Warning”, MB_OK|MB_ICONHAND);
return NULL;
}

// Load proxy DLL
HMODULE hModuleProxy=LoadLibrary(szProxyPath);
if (!hModuleProxy)
{
MessageBox(GetActiveWindow(), “Failed to load proxy”, “Warning”, MB_OK|MB_ICONHAND);
return NULL;
}

// Get entry point
PFNBRIDGEMAIN pfnBridgeMain=(PFNBRIDGEMAIN)GetProcAddress(hModuleProxy, “BridgeMain”);
if (!pfnBridgeMain)
{
FreeLibrary(hModuleProxy);
MessageBox(GetActiveWindow(), “BridgeMain entry point not found”, “JBridge”, MB_OK|MB_ICONHAND);
return NULL;
}

return pfnBridgeMain( audiomaster, szPath );

}

//##########################################################################//

Advertisements

 
%d bloggers like this: