1

我对 Visual C++ 很陌生……我目前正在从事的项目是使用 VC++ 创建从 Digibee 接受的输入日志。

关于 Digibee 的信息:http ://www.pc-control.co.uk/digibee_info.htm手册中有加载 DLL、调用函数等的基本代码。

对于一些功能,代码似乎可以正常工作(经过一些修改)......问题是:

  1. Init() - 不接受任何参数,但是当我对其进行编码时,我必须传递一个参数才能使其工作;我通过0

  2. ReadAnalogueInputs() - 应该接受 4 个参数,但是当我传递 4 个时,它说参数太多。当我成功通过一个..builds 但随后给出 System.AccessViolation 异常时工作正常。

请帮我!

    // Header file for use with dgb.dll

     typedef bool   (*Type_InitDgb)();                              
     typedef bool   (*Type_ReadInputs)(int *inputs);
     typedef bool   (*Type_SetOutputs)(int outputs);
     typedef bool   (*Type_ReadAnalogueInputs)(int *aip1, int *aip2, int *aip3, int *aip4);
     typedef bool   (*Type_SetSensitivity)(int sensitivity);

//源文件

    private: System::Void btn_Click(System::Object^  sender, System::EventArgs^  e) {
    HINSTANCE DgbHandle = LoadLibrary(TEXT("dgb.dll"));
             if (DgbHandle==NULL)
                btn->Text="Error";
             else
             {
             btn->Text="Initialized";
             this->progressBar1->Value=100;
             }

             textBox1->Text="Obtaining pointers\n";
                             TypeInitDgb InitDgb;
             TypeSetOutputs SetOutputs;
             TypeReadInputs ReadInputs;
             TypeReadAnalogueInputs ReadAnalogueInputs;
             TypeSetSensitivity SetSensitivity;
             InitDgb =                   (TypeInitDgb)GetProcAddress(HMODULE(DgbHandle),"InitDgb");
             SetOutputs = (TypeSetOutputs)GetProcAddress(HMODULE(DgbHandle),"SetOutputs");
             ReadInputs = (TypeReadInputs)GetProcAddress(HMODULE(DgbHandle),"ReadInputs");
             ReadAnalogueInputs = (TypeReadAnalogueInputs)GetProcAddress(HMODULE(DgbHandle),"ReadAnalogueInputs");
             SetSensitivity = (TypeSetSensitivity)GetProcAddress(HMODULE(DgbHandle),"SetSensitivity");
             this->progressBar2->Value=100;
             textBox1->Text="Pointers obtained";

             status=InitDgb(0);

             if(status==1)
             {
                 textBox1->Text="Digibee initialized";
                 this->progressBar3->Value=100;
                 SetOutputs(LPCTSTR(0x0001));
                 //SetOutputs(LPCSTR(15));
             }
                             int a1,a2,a3,a4;


             ReadAnalogueInputs(LPCTSTR(&a1));  

}

4

0 回答 0