本文介绍了从其他dll调用dll函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是程序员,但可以做一点点编程.
我正在为特定内容编写该程序.我有一个来自fxcm(forex broker)的dll文件,可以对其进行API调用,并且在这里可以正常工作的代码是:

I am not a programmer but can do little bit of programming.
I am writing this program for specific thing. I have a dll file from fxcm(forex broker) to which i can do API calls and its working fine here is the code:

#include<iostream>
#import "C:\\Program Files\\Candleworks\\FXOrder2Go\\fxcore.dll"

int main(int argc, char *argv[])
{
    FXCore::ICoreAutPtr core;
    FXCore::ITradeDeskAutPtr tradeDesk;

    CoInitialize(NULL);
    HRESULT hr = core.CreateInstance(__uuidof(FXCore::CoreAut));
    if (FAILED(hr))
    {
        printf("Core creation failed %08x", hr);
        return -1;
    }

    try
    {
        tradeDesk = core->CreateTradeDesk(L"trader");
    }
    catch (_com_error e)
    {
        printf("Trade desk creation failed: %S", (const wchar_t *)e.Description());
        return -1;
    }

    try
    {
        tradeDesk->Login(L"xxxx", L"xxx", L"http://www.fxcorporate.com", L"Demo");
    }
    catch (_com_error e)
    {
        tradeDesk->Logout();
        printf("Can't login : %S", (const wchar_t *)e.Description());
        return -1;
    }

    _bstr_t acct_id;
    int base_unit_size;
    try
    {
        FXCore::ITableAutPtr table = tradeDesk->FindMainTable(L"Accounts");
        acct_id = table->CellValue(1, L"AccountID");
        base_unit_size = table->CellValue(1, L"BaseUnitSize");
        printf("%S %i\n", (const wchar_t *)acct_id, base_unit_size);
		system("PAUSE");
    }
    catch (_com_error e)
    {
        tradeDesk->Logout();
        printf("Can't get account info : %S", (const wchar_t *)e.Description());
        return -1;
    }

    _variant_t order_id, dealer_i;
    try
    {
        tradeDesk->OpenTrade(acct_id, L"USD/JPY", VARIANT_TRUE, base_unit_size, 0, L"", 0, 0, 0, 0, &order_id, &dealer_i);
    }
    catch (_com_error e)
    {
        tradeDesk->Logout();
        printf("Can't open a trade : %S", (const wchar_t *)e.Description());
		system("PAUSE");
        return -1;
    }

    printf("order id %S", (const wchar_t *)(_bstr_t)order_id);
	system("PAUSE");

    tradeDesk->Logout();
}


//Now, i have created other unmanaged dll which i use with MT4(forex application ) and it is working fine too

#include <stdafx.h>

//----
#define MT4_EXPFUNC __declspec(dllexport)
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
  {
//----
     switch(ul_reason_for_call)
     {
      case DLL_PROCESS_ATTACH:
      case DLL_THREAD_ATTACH:
      case DLL_THREAD_DETACH:
      case DLL_PROCESS_DETACH:
         break;
     }
//----
   return(TRUE);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

  MT4_EXPFUNC char* __stdcall LogIn(char *id, char *password)
  {

	  return("logedin");
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall GetIntValue(const int ipar)
{

   return(ipar);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC char* __stdcall GetStringValue(char *spar)
{

   return(spar);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

MT4_EXPFUNC char* __stdcall OpenOrder(char *type, char *inst, double lot)
{

   return("open order");
}
</stdafx.h></iostream>


我也有.def和.h文件,但我没有附加它们.

我的问题:

我想调用从第一个程序到第二个程序的所有函数,而我不再想要第一个程序,则意味着
在我的第一个程序中,我导入了.dll文件,我想在第二个程序中导入该文件并调用那些函数.我该怎么办?

谢谢


I have .def and .h file as well but i didn''t attach them.

My Issue:

I want to call all the function from first program to second program and i dont want first program anymore then means
in my first program i imported .dll file, i want to import that in second program and call those function. How do i do that?

Thank You

推荐答案


这篇关于从其他dll调用dll函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:22
查看更多