EDN Admin
Well-known member
Hi! Let me first show the code:
FinalControlCf30.h -> DLL file type WIN32
<pre class="prettyprint #pragma once
#ifdef FINALCONTROLCF30_EXPORTS
#define FINALCONTROLCF30_API __declspec(dllexport)
#else
#define FINALCONTROLCF30_API __declspec(dllimport)
#endif
class FINALCONTROLCF30_API Initialize
{
public: int List();// create and get list
unsigned long ftstatus;
unsigned long ftHandle;
FT_DEVICE_LIST_INFO_NODE *devInfo; //**this is where i get the C2143**
unsigned long numDevs;
double Configure(); //Configures the device
int iVel;
char szBufferWrite[40];
char szBufferRead[40];
//DWORD dwBytesWritten; //used for LPDWORD
//DWORD dwBytesReturned; //used for LPDWORD
int Relative(); //Move relative to current position
double LCnt;
char axis;
int AbsPos(); //move to absolute position
int SetRamp(); //to set the ramp
unsigned long iAnswer12;
int SetCounter(); //to set the counter
int StopFast(); //to stop the device, different from FT_Close
int GetRamp(); //to get ramp value
int GetCounter(); // to get counter value
unsigned long Close(); //to simply close the device.
};[/code]
FinalControlCF30.cpp -> DLL file type WIN32
<pre class="prettyprint // FinalControlCf30.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include <iostream>
#include "ftd2xx.h"
#include "FinalControlCF30.h"
//#include <WinDef.h>
#include <Windows.h>
#include <stdint.h>
#include <strsafe.h> //for stringcbprintfa
using namespace std;
DWORD dwBytesWritten=0; //used for LPDWORD
DWORD dwBytesReturned=0; //used for LPDWORD
int Initialize::List()
{
//FT_STATUS ftstatus;
//FT_DEVICE_LIST_INFO_NODE *devInfo;
//DWORD numDevs;
//create device infolist
ftstatus = FT_CreateDeviceInfoList(&numDevs);
if (ftstatus == FT_OK)
{
cout<<"Number of devices is %dn",numDevs;
}
else
{
cout<<"Create List Failed";
return (FT_DEVICE_NOT_FOUND);
}
if (numDevs > 0) // for GET DEVICE INFO LIST
{
//allocate storage for list based on numDevs
devInfo=(FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs);
//get device info list
ftstatus = FT_GetDeviceInfoList(devInfo,&numDevs);
if(ftstatus == FT_OK)
{
for (unsigned int i = 0;i<numDevs; i++)
{
cout<<"Dev %d:n",i;
cout<<"Flags = 0x%xn",devInfo.Flags;
cout<<"Type = 0x%xn", devInfo.Type;
cout<<"ID= 0x%xn",devInfo.ID;
cout<<"LocId= 0x%xn",devInfo.LocId;
cout<<"SerialNumber= %sn", devInfo.SerialNumber;
cout<<"Description= %sn", devInfo.Description;
cout<<"fthandle=0x%xn" , devInfo.ftHandle;
}
}
}
};
double Initialize::Configure()
{
ftstatus= FT_SetDivisor(ftHandle,5); //600000 bits/s i.e. 3Mhz/5= 600000.
ftstatus= FT_SetDataCharacteristics(ftHandle,FT_BITS_8,FT_STOP_BITS_1,FT_PARITY_NONE);
ftstatus= FT_ResetDevice(ftHandle);
ftstatus= FT_SetTimeouts(ftHandle,100,100);
cout<<"Device Configured and ready to use!";
return (FT_OK);
};
int Initialize::Relative()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"PM,%d,%d,%dr", axis,(short) iVel,LCnt);
ftstatus = FT_Purge(ftHandle,FT_PURGE_TX|FT_PURGE_RX);
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD)strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read(ftHandle,szBufferRead,24,&dwBytesReturned);
cout<<"moved to relative position";
return 0;
};
int Initialize::AbsPos()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"PA,%d,%d,%dr", axis,(short) iVel,LCnt);
ftstatus = FT_Purge(ftHandle,FT_PURGE_TX|FT_PURGE_RX);
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD)strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read(ftHandle,szBufferRead,22,&dwBytesReturned);
cout<<"moved to absolute position";
return (0);
};
int Initialize::SetRamp()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"SR,1,%dr",(BYTE)LCnt);
ftstatus = FT_Purge(ftHandle,FT_PURGE_TX|FT_PURGE_RX);
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD)strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read(ftHandle,szBufferRead,iAnswer12,&dwBytesReturned);
return(0);
};
int Initialize::SetCounter()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"SC,1,%dr", LCnt);
ftstatus = FT_Purge(ftHandle, FT_PURGE_TX | FT_PURGE_RX );
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD) strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read (ftHandle,szBufferRead,15,&dwBytesReturned);
return(0);
};
int Initialize::StopFast()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"SF,7r");
ftstatus = FT_Purge(ftHandle, FT_PURGE_TX | FT_PURGE_RX );
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD) strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read (ftHandle,szBufferRead,5,&dwBytesReturned);
return(0);
};
int Initialize::GetRamp()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"GR,1r", (BYTE)LCnt);
ftstatus = FT_Purge (ftHandle, FT_PURGE_TX | FT_PURGE_RX );// _TX - Out // _RX - In
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD) strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read (ftHandle,szBufferRead,12,&dwBytesReturned);
return(0);
};
int Initialize::GetCounter()
{
ftstatus = FT_Purge (ftHandle, FT_PURGE_TX | FT_PURGE_RX );// _TX - Out // _RX - In
ftstatus = FT_Write(ftHandle,"GC,1r",(DWORD) strlen("GC,1r"),&dwBytesWritten);
ftstatus = FT_Read (ftHandle,szBufferRead,17,&dwBytesReturned);
return(FT_Read(ftHandle,szBufferRead,17,&dwBytesReturned));
};
unsigned long Initialize::Close()
{
ftstatus = FT_Open(0,&ftHandle);
if(ftstatus==FT_OK)
{
FT_Close(ftHandle);
}
else
{
cout<<"No Initial Response of device";
return(0);
}
};
int main()
{
/*Initialize ObjList;
ObjList.List();*/
}[/code]
No issues with the CPP as far as i understand.
FinalExe.cpp -> EXE file included in the solution, type WIN32.
<pre class="prettyprint #include "stdafx.h"
#include "FinalControlCF30.h"
#include <windows.h>
#include <stdint.h>
#include <strsafe.h>
#include "ftd2xx.h"
#include <windef.h>
int main()
{
Initialize <a list of objects>; // nothing important here just list of objects for the class initialize
return 0;
}[/code]
Now the problem,
1. As indicated in <FinalControlCF30.h>, that particular line shows ERROR C2143. why?
2. When i compile the DLL alone there is no error. it compiles perfectly fine.
3. the indicated error line belongs to the following code in ftd2xx.h as shown below:
<pre class="prettyprint typedef struct _ft_device_list_info_node {
ULONG Flags;
ULONG Type;
ULONG ID;
DWORD LocId;
char SerialNumber[16];
char Description[64];
FT_HANDLE ftHandle;
} FT_DEVICE_LIST_INFO_NODE; //here it is[/code]
<br/>
so please help, what seems to be the problem?
4. Also i get the warning of "inconsistent DLL linkage", as it is level one warning i have ignored but is there anything i can change?
5. this error is also followed by C4430, after some search on MSDN it says its warning. what does it mean? it shows as an error but is actually a warning by MSDN. Its for the same line as indicated in FinalControlCf30.h
the DLL<FinalControlCF30.h and FinalControlCF30.cpp> and EXE<FinalExe> are linked using the project properties and also i have place the required DLL and LIB files in the folder of <FinalExe>.
I am not extremely experienced in .Net Unmanaged C++.
Thanks in ADVANCE!!
<br/>
View the full article
FinalControlCf30.h -> DLL file type WIN32
<pre class="prettyprint #pragma once
#ifdef FINALCONTROLCF30_EXPORTS
#define FINALCONTROLCF30_API __declspec(dllexport)
#else
#define FINALCONTROLCF30_API __declspec(dllimport)
#endif
class FINALCONTROLCF30_API Initialize
{
public: int List();// create and get list
unsigned long ftstatus;
unsigned long ftHandle;
FT_DEVICE_LIST_INFO_NODE *devInfo; //**this is where i get the C2143**
unsigned long numDevs;
double Configure(); //Configures the device
int iVel;
char szBufferWrite[40];
char szBufferRead[40];
//DWORD dwBytesWritten; //used for LPDWORD
//DWORD dwBytesReturned; //used for LPDWORD
int Relative(); //Move relative to current position
double LCnt;
char axis;
int AbsPos(); //move to absolute position
int SetRamp(); //to set the ramp
unsigned long iAnswer12;
int SetCounter(); //to set the counter
int StopFast(); //to stop the device, different from FT_Close
int GetRamp(); //to get ramp value
int GetCounter(); // to get counter value
unsigned long Close(); //to simply close the device.
};[/code]
FinalControlCF30.cpp -> DLL file type WIN32
<pre class="prettyprint // FinalControlCf30.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include <iostream>
#include "ftd2xx.h"
#include "FinalControlCF30.h"
//#include <WinDef.h>
#include <Windows.h>
#include <stdint.h>
#include <strsafe.h> //for stringcbprintfa
using namespace std;
DWORD dwBytesWritten=0; //used for LPDWORD
DWORD dwBytesReturned=0; //used for LPDWORD
int Initialize::List()
{
//FT_STATUS ftstatus;
//FT_DEVICE_LIST_INFO_NODE *devInfo;
//DWORD numDevs;
//create device infolist
ftstatus = FT_CreateDeviceInfoList(&numDevs);
if (ftstatus == FT_OK)
{
cout<<"Number of devices is %dn",numDevs;
}
else
{
cout<<"Create List Failed";
return (FT_DEVICE_NOT_FOUND);
}
if (numDevs > 0) // for GET DEVICE INFO LIST
{
//allocate storage for list based on numDevs
devInfo=(FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FT_DEVICE_LIST_INFO_NODE)*numDevs);
//get device info list
ftstatus = FT_GetDeviceInfoList(devInfo,&numDevs);
if(ftstatus == FT_OK)
{
for (unsigned int i = 0;i<numDevs; i++)
{
cout<<"Dev %d:n",i;
cout<<"Flags = 0x%xn",devInfo.Flags;
cout<<"Type = 0x%xn", devInfo.Type;
cout<<"ID= 0x%xn",devInfo.ID;
cout<<"LocId= 0x%xn",devInfo.LocId;
cout<<"SerialNumber= %sn", devInfo.SerialNumber;
cout<<"Description= %sn", devInfo.Description;
cout<<"fthandle=0x%xn" , devInfo.ftHandle;
}
}
}
};
double Initialize::Configure()
{
ftstatus= FT_SetDivisor(ftHandle,5); //600000 bits/s i.e. 3Mhz/5= 600000.
ftstatus= FT_SetDataCharacteristics(ftHandle,FT_BITS_8,FT_STOP_BITS_1,FT_PARITY_NONE);
ftstatus= FT_ResetDevice(ftHandle);
ftstatus= FT_SetTimeouts(ftHandle,100,100);
cout<<"Device Configured and ready to use!";
return (FT_OK);
};
int Initialize::Relative()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"PM,%d,%d,%dr", axis,(short) iVel,LCnt);
ftstatus = FT_Purge(ftHandle,FT_PURGE_TX|FT_PURGE_RX);
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD)strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read(ftHandle,szBufferRead,24,&dwBytesReturned);
cout<<"moved to relative position";
return 0;
};
int Initialize::AbsPos()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"PA,%d,%d,%dr", axis,(short) iVel,LCnt);
ftstatus = FT_Purge(ftHandle,FT_PURGE_TX|FT_PURGE_RX);
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD)strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read(ftHandle,szBufferRead,22,&dwBytesReturned);
cout<<"moved to absolute position";
return (0);
};
int Initialize::SetRamp()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"SR,1,%dr",(BYTE)LCnt);
ftstatus = FT_Purge(ftHandle,FT_PURGE_TX|FT_PURGE_RX);
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD)strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read(ftHandle,szBufferRead,iAnswer12,&dwBytesReturned);
return(0);
};
int Initialize::SetCounter()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"SC,1,%dr", LCnt);
ftstatus = FT_Purge(ftHandle, FT_PURGE_TX | FT_PURGE_RX );
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD) strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read (ftHandle,szBufferRead,15,&dwBytesReturned);
return(0);
};
int Initialize::StopFast()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"SF,7r");
ftstatus = FT_Purge(ftHandle, FT_PURGE_TX | FT_PURGE_RX );
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD) strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read (ftHandle,szBufferRead,5,&dwBytesReturned);
return(0);
};
int Initialize::GetRamp()
{
StringCbPrintfA(szBufferWrite,sizeof(szBufferWrite),"GR,1r", (BYTE)LCnt);
ftstatus = FT_Purge (ftHandle, FT_PURGE_TX | FT_PURGE_RX );// _TX - Out // _RX - In
ftstatus = FT_Write(ftHandle,szBufferWrite,(DWORD) strlen(szBufferWrite),&dwBytesWritten);
ftstatus = FT_Read (ftHandle,szBufferRead,12,&dwBytesReturned);
return(0);
};
int Initialize::GetCounter()
{
ftstatus = FT_Purge (ftHandle, FT_PURGE_TX | FT_PURGE_RX );// _TX - Out // _RX - In
ftstatus = FT_Write(ftHandle,"GC,1r",(DWORD) strlen("GC,1r"),&dwBytesWritten);
ftstatus = FT_Read (ftHandle,szBufferRead,17,&dwBytesReturned);
return(FT_Read(ftHandle,szBufferRead,17,&dwBytesReturned));
};
unsigned long Initialize::Close()
{
ftstatus = FT_Open(0,&ftHandle);
if(ftstatus==FT_OK)
{
FT_Close(ftHandle);
}
else
{
cout<<"No Initial Response of device";
return(0);
}
};
int main()
{
/*Initialize ObjList;
ObjList.List();*/
}[/code]
No issues with the CPP as far as i understand.
FinalExe.cpp -> EXE file included in the solution, type WIN32.
<pre class="prettyprint #include "stdafx.h"
#include "FinalControlCF30.h"
#include <windows.h>
#include <stdint.h>
#include <strsafe.h>
#include "ftd2xx.h"
#include <windef.h>
int main()
{
Initialize <a list of objects>; // nothing important here just list of objects for the class initialize
return 0;
}[/code]
Now the problem,
1. As indicated in <FinalControlCF30.h>, that particular line shows ERROR C2143. why?
2. When i compile the DLL alone there is no error. it compiles perfectly fine.
3. the indicated error line belongs to the following code in ftd2xx.h as shown below:
<pre class="prettyprint typedef struct _ft_device_list_info_node {
ULONG Flags;
ULONG Type;
ULONG ID;
DWORD LocId;
char SerialNumber[16];
char Description[64];
FT_HANDLE ftHandle;
} FT_DEVICE_LIST_INFO_NODE; //here it is[/code]
<br/>
so please help, what seems to be the problem?
4. Also i get the warning of "inconsistent DLL linkage", as it is level one warning i have ignored but is there anything i can change?
5. this error is also followed by C4430, after some search on MSDN it says its warning. what does it mean? it shows as an error but is actually a warning by MSDN. Its for the same line as indicated in FinalControlCf30.h
the DLL<FinalControlCF30.h and FinalControlCF30.cpp> and EXE<FinalExe> are linked using the project properties and also i have place the required DLL and LIB files in the folder of <FinalExe>.
I am not extremely experienced in .Net Unmanaged C++.
Thanks in ADVANCE!!
<br/>
View the full article