i have created one dll to connect to the com object of one application and call a method of the com. Its working fine. but with one issue. Every time dll is access it keeps creating new instance, so i to avoid this i created global variables, but seems its now working.

connectApi - this function to be called only once to create com instance
sendOrder - this function will be called repeatably as need be which shud use the com object pointer created by the connectApi function.


here is the code:
Code:
IPlusapi *pNestApp;
HRESULT hr;


BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                     )
{

    return TRUE;
}

 int __stdcall connectApi(char* apiname)
{
    CoInitialize(NULL);

    const CLSID clsid = {0x91741D4F, 0x948B, 0x46A0, {0xA2,0xCC,0x0B,0x92,0x5c,0x4f,0x5e,0x17}};
    hr = CoCreateInstance(clsid,NULL, CLSCTX_LOCAL_SERVER, IID_IPlusapi, (void **)&pNestApp);

    if(FAILED(hr)) {
        MessageBox(NULL,"Nest Plus API Not registered properly","ERROR",NULL);
        return(-1);
    }
    else {
         pNestApp->SetObjectName(apiname);
         
         return(1);
    }
     
}



void __stdcall sendOrder(char* type,char* refno,char*exch,char* sym,char* valid, char* ordertype,
                                     long qty,double price,double triggerprice,long disqty,char* prodtype,char* clientid)
{
    
    if(SUCCEEDED(hr))
    {
        pNestApp->PlaceOrder(type,refno,exch,sym,valid,ordertype,qty,price,triggerprice,disqty,prodtype,clientid);
      
    }
}

Last edited by shabbir; 20Sep2012 at 09:54.. Reason: Code blocks