LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

including dll from C++

Hi!
 
In my project I use dll from C++. Some functions do not work, and I don't know, its troubles of dll, or call convension difference.
 
My question: are you can see something wrong in my code, or it's dll troubles?
 
Thanks in advance.
 
Rombar
 
Code and header example:
 
1. Code
 
#include <userint.h>
#include <windows.h>
#include <ansi_c.h>
#include "multiple_cyclonepromax_programming.h"
void main(void)
{
 unsigned int iRet, ttt;
 unsigned short nnn=0;
 char Buf[40]={0}, szTemp[40]={0};
 HINSTANCE hinstLib=NULL;
  
 type_set_local_machine_ip_number set_local_machine_ip_number;
 type_connect_to_cyclonepromax_by_ip connect_to_cyclonepromax_by_ip;
 type_get_firmware_version get_firmware_version;
 type_reset_cyclonepromax reset_cyclonepromax;
 type_update_image_with_file update_image_with_file;
 type_compare_image_with_file compare_image_with_file;
 type_get_image_description get_image_description;
 type_erase_all_cyclone_images erase_all_cyclone_images;
 type_count_cyclonepromax_images count_cyclonepromax_images;
 type_add_image_to_cyclone add_image_to_cyclone;
 type_toggle_power_no_background_entrance toggle_power_no_background_entrance;
 type_disconnect_from_cyclonepromax disconnect_from_cyclonepromax;
 type_get_last_error_code get_last_error_code;
  
 hinstLib = LoadLibrary("CYCLONE_CONTROL.dll");
 
 connect_to_cyclonepromax_by_ip = (type_connect_to_cyclonepromax_by_ip)GetProcAddress(hinstLib, "connect_to_cyclonepromax_by_ip");
 get_firmware_version = (type_get_firmware_version)GetProcAddress(hinstLib, "get_firmware_version");
 reset_cyclonepromax = (type_reset_cyclonepromax)GetProcAddress(hinstLib, "reset_cyclonepromax");
 update_image_with_file = (type_update_image_with_file)GetProcAddress(hinstLib, "update_image_with_file");
 compare_image_with_file = (type_compare_image_with_file)GetProcAddress(hinstLib, "compare_image_with_file");
 get_image_description = (type_get_image_description)GetProcAddress(hinstLib, "get_image_description");
 erase_all_cyclone_images = (type_erase_all_cyclone_images)GetProcAddress(hinstLib, "erase_all_cyclone_images");
 count_cyclonepromax_images = (type_count_cyclonepromax_images)GetProcAddress(hinstLib, "count_cyclonepromax_images");
 add_image_to_cyclone = (type_add_image_to_cyclone)GetProcAddress(hinstLib, "add_image_to_cyclone");
 toggle_power_no_background_entrance = (type_toggle_power_no_background_entrance)GetProcAddress(hinstLib, "toggle_power_no_background_entrance");
 set_local_machine_ip_number = (type_set_local_machine_ip_number)GetProcAddress(hinstLib, "set_local_machine_ip_number");
 disconnect_from_cyclonepromax = (type_disconnect_from_cyclonepromax)GetProcAddress(hinstLib, "disconnect_from_cyclonepromax");
 get_last_error_code = (type_get_last_error_code)GetProcAddress(hinstLib, "get_last_error_code");
 
 set_local_machine_ip_number("10.10.5.10");               // ???
 iRet = connect_to_cyclonepromax_by_ip("10.10.5.3"); // pass
 strcpy(szTemp, get_firmware_version(iRet));               // pass, returned version "6.77.00" 
 ttt = reset_cyclonepromax(iRet, 3000);                          // pass, return code - 1 (TRUE)
 strcpy(szTemp, get_firmware_version(iRet));               // pass, return error - 0
 strcpy(szTemp, get_image_description(iRet, 1));         // pass, return description - "2/14/2008 3:29:25 PM"
 strcpy(szTemp, "c:\\probe\\T2_Sap_file_demo.SAP");        
 ttt = compare_image_with_file(iRet, szTemp, 1);          // fail, all LEDs are off, return code -  0 (FALSE),
                                                                                         // timeout aproximate 1,5 min, error code - 61166 (0xEEEE)
 
2. Header
 
#if !defined(PE_CYCLONEPROMAX_INTERFACE_ROUTINES)
#define PE_CYCLONEPROMAX_INTERFACE_ROUTINES
typedef unsigned int bool;
typedef unsigned int (_cdecl *type_check_allowed_number_of_cyclonepromax_connections)(void);
typedef void (_cdecl *type_increase_number_of_allowed_cyclonepromax_connections)(char *license_string);
typedef void (_cdecl *type_set_local_machine_ip_number)(char *ip_number);
typedef unsigned int (_cdecl *type_connect_to_cyclonepromax_by_ip)(char *port_identifier);
typedef bool (_cdecl *type_disconnect_from_cyclonepromax)(unsigned long cyclonepromaxhandle);
typedef bool (_cdecl *type_reset_cyclonepromax)(unsigned long cyclonepromaxhandle, unsigned long reset_delay_in_ms);
typedef char *(_cdecl *type_get_firmware_version)(unsigned long cyclonepromaxhandle);
typedef char *(_cdecl *type_get_image_description)(unsigned long cyclonepromaxhandle, unsigned char image_id);
typedef bool (_cdecl *type_compare_image_with_file)(unsigned long cyclonepromaxhandle, char *aFile, unsigned char image_id);
typedef bool (_cdecl *type_update_image_with_file)(unsigned long cyclonepromaxhandle, char *aFile);
typedef bool (_cdecl *type_erase_all_cyclone_images)(unsigned long cyclonepromaxhandle);
typedef unsigned int (_cdecl *type_add_image_to_cyclone)(unsigned long cyclonepromaxhandle, char *aFile);
typedef unsigned char (_cdecl *type_count_cyclonepromax_images)(unsigned long cyclonepromaxhandle);
typedef bool (_cdecl *type_START_execute_all_commands)(unsigned long cyclonepromaxhandle, unsigned char image_id);
typedef bool (_cdecl *type_START_dynamic_program_bytes)(unsigned long cyclonepromaxhandle, unsigned long target_address, unsigned short data_length, char *buffer);
typedef unsigned int (_cdecl *type_check_STARTED_cyclonepromax_status)(unsigned long cyclonepromaxhandle);
typedef unsigned short (_cdecl *type_get_last_error_code)(unsigned long cyclonepromaxhandle);
typedef unsigned int (_cdecl *type_get_last_error_addr)(unsigned long cyclonepromaxhandle);
typedef bool (_cdecl *type_dynamic_read_bytes)(unsigned long cyclonepromaxhandle, unsigned long target_address, unsigned short data_length, char *buffer);
typedef bool (_cdecl *type_pro_set_active_security_code)(unsigned long cyclonepromaxhandle, char *buffer);
typedef bool (_cdecl *type_toggle_power_no_background_entrance)(unsigned long cyclonepromaxhandle);

extern type_check_allowed_number_of_cyclonepromax_connections check_allowed_number_of_cyclonepromax_connections;
extern type_increase_number_of_allowed_cyclonepromax_connections increase_number_of_allowed_cyclonepromax_connections;
extern type_set_local_machine_ip_number set_local_machine_ip_number;
extern type_connect_to_cyclonepromax_by_ip connect_to_cyclonepromax_by_ip;
extern type_disconnect_from_cyclonepromax disconnect_from_cyclonepromax;
extern type_reset_cyclonepromax reset_cyclonepromax;
extern type_get_firmware_version get_firmware_version;
extern type_get_image_description get_image_description;
extern type_compare_image_with_file compare_image_with_file;
extern type_update_image_with_file update_image_with_file;
extern type_erase_all_cyclone_images erase_all_cyclone_images;
extern type_add_image_to_cyclone add_image_to_cyclone;
extern type_count_cyclonepromax_images count_cyclonepromax_images;
extern type_START_execute_all_commands START_execute_all_commands;
extern type_START_dynamic_program_bytes START_dynamic_program_bytes;
extern type_check_STARTED_cyclonepromax_status check_STARTED_cyclonepromax_status;
extern type_get_last_error_code get_last_error_code;
extern type_get_last_error_addr get_last_error_addr;
extern type_dynamic_read_bytes dynamic_read_bytes;
extern type_pro_set_active_security_code pro_set_active_security_code;
extern type_toggle_power_no_background_entrance toggle_power_no_background_entrance;
#endif
0 Kudos
Message 1 of 2
(3,955 Views)

Hi Rombar,

I didn't notice anything blatantly wrong at first glance. I had a couple of questions:

  1. How are you including the dll in your project? Is the header autogenerated?
  2. Have you tried the dll from another language to make sure the dll actually works? Do you have the source code?
  3. What does the error code 61166 refer to? Is that documented in the C++ dll's code?
  4. What version of CVI are you using?

Also, a good resource for calling dll's from CVI is the DeveloperZone Tutorial: FAQ Using Dynamic Link Libraries with LabWindows/CVI

Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 2 of 2
(3,916 Views)