最近使用的高清设备,只提供了VC的SDK和例子,但我之前的程序是用DELPHI开发的
想在原有的程序,支持这款高清设备,想把SDK里的头文件翻译成DELPHI的。请高手看看:
#ifndef _NETCAMERA_SNAPSERVER_H_
#define _NETCAMERA_SNAPSERVER_H_
#ifndef _WIN32 //linux
#define NC_SNAP_EXT
#define CRITICAL_SECTION pthread_mutex_t
#define InitializeCriticalSection(x) pthread_mutex_init(x,NULL)
#define DeleteCriticalSection(x) pthread_mutex_destroy(x)
#define EnterCriticalSection(x) pthread_mutex_lock(x)
#define LeaveCriticalSection(x) pthread_mutex_unlock(x)
#else //windows
#define _CRTDBG_MAP_ALLOC
#include<stdlib.h>
#include<crtdbg.h>
#include<windows.h>
#ifndef NETCAMERA_SNAPSERVER_EXPORTS
#define NC_SNAP_EXT __declspec(dllimport)
#else
#define NC_SNAP_EXT __declspec(dllexport)
#endif
#endif#include <queue>
using namespace std;////////////////////////////////////////////////////////////////////////////////
//STRUCT DEFINE
#ifndef _FRAME_HEADER_
#define _FRAME_HEADER_
struct FRAME_HEADER
{
unsigned short w;               //image width
unsigned short h;               //image height

unsigned short bits;            //bits 
unsigned short format;          //data type(0:gray 1:bayer_rg 2:bayer_GR 3:bayer_bg 5:RGB 6:YUV422 7:JPEG 8:MPEG4 9:H264)

unsigned short frame_type;      //frame type:(0:normal frame 1:snap frame 2:heart-beat frame)
unsigned short frame_version;   //frame version: current set to 0x0100

unsigned long  firmware_version;//firmware version
unsigned long  device_no;       //device num

unsigned long  len;             //image size

unsigned long  speed;           //speed
unsigned long  rs232;           //rs232 info

unsigned short year;            //image cap time:year
unsigned short month;           //image cap time:month
unsigned short day;             //image cap time:day
unsigned short hour;            //image cap time:hour
unsigned short minute;          //image cap time:minute 
unsigned short second;          //image cap time:second

unsigned long ip;               //current camera ip
unsigned long frame_count;      //total snap frame number
unsigned long trigger_count;    //total trigger number
unsigned long trigger_index;    //trigger index
unsigned long frame_no;         //frame number

unsigned long gain;             //gain
unsigned long time;             //ex time
unsigned long gain_r;           //red gain
unsigned long gain_g;           //green gain
unsigned long gain_b;           //blue gain

unsigned long mode;             //camera work mode
unsigned long JpegQ;            //jpeg quality
unsigned long td1;              //td1
unsigned long td2;              //td2

unsigned long trig_chl;         //trigger channel
unsigned long msecond;          //image cap time:msecond

unsigned long yavg;             //yavg
unsigned long mpeg_head;        //mpeg4/h264 header flag
unsigned long st_usr_param;     //soft trigger user param
unsigned long rev[7];           //rev

unsigned char user_info[64];    //user info
};
#endifclass NC_SNAP_EXT NetCamera_SnapServer  
{
public:
int Init();
int StartRecv(unsigned short port);
int GetImage(unsigned char* buf,int &total_length);
int UnInit();
int AddImage(unsigned char* pImage);
public:
unsigned int GetSocket();
unsigned short GetRecvPort();
NetCamera_SnapServer();
virtual ~NetCamera_SnapServer();
private:
int m_nMaxQueueLength; /*max length of image queue*/
unsigned short m_nPort; /*listen port*/
unsigned int m_nSocket; /*listen socket*/
queue<unsigned char*>* m_pImageQueue; /*image queue*/
CRITICAL_SECTION m_cs; /*mutex the queue*/
};#endif前面的宏定义,我想,只使用在WINDOWS下面,可以不考虑Linux环境。
#define _CRTDBG_MAP_ALLOC
...
...
#define NC_SNAP_EXT __declspec(dllimport)
能大概解释下上面这两段有什么意义吗?
class NC_SNAP_EXT NetCamera_SnapServer  
这个类的继承关系,不知在DELPHI中要如何处理
virtual ~NetCamera_SnapServer();
我知道C++里“~类名”,应该就是解构函数了,但这个解构函数的virtual要怎么理解呢?queue<unsigned char*>* m_pImageQueue; /*image queue*/
在类的私有成员中,的这个pImageQueue,是什么指针,我觉得像是指针的指针?queue关键字,有什么意义?CRITICAL_SECTION m_cs; /*mutex the queue*/
这里这个,从VC定义,能猜到是“互斥对象”,在WinBase.h里有定义这个结构,不知DELPHI有没有对应的?如果没有,自己能不能写一个相同的结构类型?
出来得早,那时在学校时都是学的Basic和FoxBase,关于VC都在后来工作中慢慢看到, 基础很差,希望各位达达不要介意。请多多指教。

解决方案 »

  1.   

    别瞎忙了,导出类,转不了delphi
    给你个建议,用vc写一个中间dll 作为2者之间的转换
      

  2.   

    自己用VC做一个封装然后提供delphi调用这个方法不错
      

  3.   

    VC没怎么用过,这两天,试着做了下DLL,成了。现在碰到的问题是这样:#include "stdafx.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <direct.h>
    #include "NetCamera_SnapServer.h"
    extern "C" _declspec(dllexport) int SnapServerInit();int SnapServerInit()
    {
    NetCamera_SnapServer server;  //如果有这句,就编译不过,没有,就可以。
             return 0;
    }报错的内容是:1>正在链接...
    1>   正在创建库 F:\Object\vc\SnapServerDll\Debug\SnapServerDll.lib 和对象 F:\Object\vc\SnapServerDll\Debug\SnapServerDll.exp
    1>SnapServerDll.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: virtual __thiscall NetCamera_SnapServer::~NetCamera_SnapServer(void)" (__imp_??1NetCamera_SnapServer@@UAE@XZ),该符号在函数 _SnapServerInit 中被引用
    1>SnapServerDll.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall NetCamera_SnapServer::NetCamera_SnapServer(void)" (__imp_??0NetCamera_SnapServer@@QAE@XZ),该符号在函数 _SnapServerInit 中被引用
    1>F:\Object\vc\SnapServerDll\Debug\SnapServerDll.dll : fatal error LNK1120: 2 个无法解析的外部命令为什么会报这样的错呢?
      

  4.   

    哦哦哦,发现问题了。#ifndef _WIN32
    #else
    #pragma comment(lib,"NetCamera_SnapServer.lib")
    #endif把这段写到 “#include "NetCamera_SnapServer.h"”下,把lib文件拷到工程里,程序就编译过了。哪位达达能解释下 lib 库文件在VC里的关系。
    我在使用DELPHI时,好像没有碰到有LIB文件的问题样呢?lib是VC特有的吗?