vc中的声明
#ifdef OSDDLL_EXPORTS
#define OSDDLL_API __declspec(dllexport)
#else
#define OSDDLL_API __declspec(dllimport)
#endiftypedef struct _TIMESTRUCT
{
unsigned char cYear;
unsigned char cMonth;
unsigned char cDay;
unsigned char cHour;
unsigned char cMinute;
unsigned char cSecond;
}TIMESTRUCT;
// This class is exported from the OSDDLL.dll
class OSDDLL_API COSDDLL {
public:
COSDDLL(void);
// TODO: add your methods here.
};extern OSDDLL_API int nOSDDLL;
OSDDLL_API BOOL OpenConnection(WORD dwPort);
OSDDLL_API BOOL CloseConnection(WORD dwPort, DWORD dwBaudRate);
OSDDLL_API BOOL SetOsdTime(TIMESTRUCT* tm);
OSDDLL_API BOOL GetOsdTime(TIMESTRUCT* tm);
OSDDLL_API BOOL SetInitCharModel(unsigned char totallen,unsigned char index, unsigned char * model);
OSDDLL_API BOOL SetDynamicCharModel(unsigned char totallen,unsigned char index, unsigned char * model);
OSDDLL_API BOOL SetInitDispInfo(unsigned char index, unsigned char xpos, 
unsigned char ypos,unsigned char blink,unsigned char backfill,unsigned char size);
OSDDLL_API BOOL SetDynamicDispInfo(unsigned char index, unsigned char xpos, 
unsigned char ypos,unsigned char blink,unsigned char backfill,unsigned char size);
OSDDLL_API BOOL DelInitCharModel();
OSDDLL_API BOOL DelDynamicCharModel();
OSDDLL_API BOOL DelInitDispInfo();
OSDDLL_API BOOL DelDynamicDispInfo(unsigned char line);  //0xff means delete all
OSDDLL_API BOOL SetDeviceID(unsigned char id1,unsigned char id2,BOOL bWriteDevice);
OSDDLL_API BOOL GetDeviceID(unsigned char& id1,unsigned char& id2);
OSDDLL_API BOOL SetTimeFormat(unsigned char format,unsigned char xpos,unsigned char ypos);
输出为osddll.dll
delphi 中仿照以上声明:
Function OpenConnection(dwPort: WORD): Bool;stdcall; external 'OSDDLL.dll';
调用时直接写OpenConnection(1);还是不行?.

解决方案 »

  1.   

    extern "C"
    {
    OSDDLL_API BOOL OpenConnection(WORD dwPort);
    OSDDLL_API BOOL CloseConnection(WORD dwPort, DWORD dwBaudRate);
    OSDDLL_API BOOL SetOsdTime(TIMESTRUCT* tm);
    OSDDLL_API BOOL GetOsdTime(TIMESTRUCT* tm);
    OSDDLL_API BOOL SetInitCharModel(unsigned char totallen,unsigned char index, unsigned char * model);
    OSDDLL_API BOOL SetDynamicCharModel(unsigned char totallen,unsigned char index, unsigned char * model);
    OSDDLL_API BOOL SetInitDispInfo(unsigned char index, unsigned char xpos, 
    unsigned char ypos,unsigned char blink,unsigned char backfill,unsigned char size);
    OSDDLL_API BOOL SetDynamicDispInfo(unsigned char index, unsigned char xpos, 
    unsigned char ypos,unsigned char blink,unsigned char backfill,unsigned char size);
    OSDDLL_API BOOL DelInitCharModel();
    OSDDLL_API BOOL DelDynamicCharModel();
    OSDDLL_API BOOL DelInitDispInfo();
    OSDDLL_API BOOL DelDynamicDispInfo(unsigned char line);  //0xff means delete all
    OSDDLL_API BOOL SetDeviceID(unsigned char id1,unsigned char id2,BOOL bWriteDevice);
    OSDDLL_API BOOL GetDeviceID(unsigned char& id1,unsigned char& id2);
    OSDDLL_API BOOL SetTimeFormat(unsigned char format,unsigned char xpos,unsigned char ypos);
    }看这样可不可以。呵呵,好久没用C/C++了,记得不太清楚了。应该是这样改
      

  2.   

    还可以用LoadLibrary和GetProcAddress动态调用.
      

  3.   

    实际上该dll并没有按照标准c方式来输出,可能使得该dll的函数名已经被编译器改变,
    你可以用vc工具DEPENDS.EXE来查看该dll的输出函数,确定其倒出函数名,后重新声明
    如:
    Function OpenConnection(dwPort: WORD): Bool;stdcall;external 'OSDDLL.dll'name '你查到的函数名';还要注意一点该函数申明时并不是声明为stdcall,应该是c风格
      

  4.   

    在你vc++的倒出函数前面添上extern"c"
    这样就可以防止添加那些不必要的字符
    如下:
    define OSDDLL_API extern"c"__declspec(dllexport)
    #else
    #define OSDDLL_API extern"c"__declspec(dllimport)
    #endif
    用depends你要一个一个函数的添加那些"_"或者"@"的字符