i have bought a k8061 interface card and i have tried the demo version which in your site and it works good…and i have tried the sample c++ code on my vs2010 and it works good…
But when i tried to write my own c++ code in my vs2010 i have many errors…really i haven’t use .dll file before in my code and i searched alot on the web but i still can’t write my own code…
Please help me…
i started new project and i’ve turned Common Language Runtime Support to “Pure MSIL /clr:pure”
and wrote this code
[code]
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Runtime::InteropServices;
void main()
{
[DllImport(“k8061.dll”, CharSet=CharSet::Ansi)]
static int OpenDevice();
int h = OpenDevice();
}[/code]
and i had many errors such as attribute not found , missing " " around Ansi … and more
I modified your code a little and made this simple CLR console application in Microsoft Visual C++ 2010. [code]// console_test1.cpp : main project file.
#include “stdafx.h”
using namespace System;
using namespace System::Runtime::InteropServices;
[DllImport(“k8061.dll”, CharSet=CharSet::Ansi)]
extern “C” int OpenDevice();
[DllImport(“k8061.dll”, CharSet=CharSet::Ansi)]
extern “C” void OutputAllDigital(int CardAddress, int Data);
int main()
{
int CardAddress = OpenDevice();
if (CardAddress >= 0)
{
Console::WriteLine(“Card #” + CardAddress + " opened.");
OutputAllDigital(CardAddress, 0x55);
}
else
{
Console::WriteLine(“Card not found”);
}
Console::WriteLine(“Press any key to quit. \n”);
Console::ReadKey();
return 0;
}[/code]Common Language Runtime Support (/clr).
The common language runtime (CLR) provides Platform Invocation Services, or PInvoke, that enables managed code to call C-style functions in native dynamic-linked libraries (DLLs).
More info: Calling Native Functions from Managed Code
http://msdn.microsoft.com/en-us/library/ms235282(v=vs.80).aspx
More about the Common Language Runtime (CLR):
http://msdn.microsoft.com/en-us/library/8bs2ecf4.aspx