各位大大你們好,
小弟最近因為研究需要,有用到headless signal hound的API
他的Library和dll都是由VC++ 2008產生的,我有使用VC++ 2008試過
可以正常的使用。但由於只能用BCB 6,所以一個簡單的呼叫動作確一直出錯。
希望有經驗大大能夠提供意見
我也使用了implib的方式來轉lib和dll但都會出現錯誤訊息如下: cannot open files.
我很確認我的路徑是對的
以下是API的header檔
MySignalhound.h
Revision History (Windows):
12 JAN 2012 Justin Crooks Created from Signal Hound code. Removed Windows dependencies.
19 APR 2012 Justin Crooks Added AD9864 recalibration support and cleaned up a bit
*/
#include "Settings.h"
#include "MeasRcvr.h"
// 0 for OK, 1 for no Signal Hound, 2 for couldn't open Signal Hound ports, 98 for no tempco file, 99 for no cal data
#define ERROR_HOUND_MISSING 1
#define ERROR_HOUND_PORTS 2
#define ERROR_HOUND_TEMPCOFILE 98
#define ERROR_HOUND_CALFILE 99
#pragma once
__declspec(dllimport) double mW2dBm(double mWIn); //Simple function to convert a reading in milliwatts to a reading in dBm.
__declspec(dllimport) double GetRBWFromIndex(int idx); //Returns RBW in Hz
class CMySignalHound
{
public:
__declspec(dllimport) CMySignalHound(void);
__declspec(dllimport) ~CMySignalHound(void);
__declspec(dllimport) int Initialize(void);
// ***** Sweep functions *****
__declspec(dllimport) int SetupForSweep(void);
__declspec(dllimport) int PreamplifierOnOff(bool onoff);
__declspec(dllimport) int SetCenterAndSpan(double cf, double span);
__declspec(dllimport) int SetStartAndStop(double start, double stop);
__declspec(dllimport) int DoSweep();
__declspec(dllimport) double GetFrequencyFromIdx(int idx);
__declspec(dllimport) int SetExternalRef();
// ***** Channel power functions *****
__declspec(dllimport) double GetACPL();
__declspec(dllimport) double GetACPR();
__declspec(dllimport) double GetCP();
// ***** Special Purpose functions *****
__declspec(dllimport) int DoPhaseNoiseSweep(int startDecade, int stopDecade, double referenceAmplitude);
__declspec(dllimport) double ReadTemperature();
__declspec(dllimport) int DoMeasuringReceiver(MEAS_RCVR_STRUCT * pMeasRcvr);
__declspec(dllimport) void * OpenAudio();
__declspec(dllimport) void CloseAudio(void * pAudioStr);
protected: //Functions for internal use only.
int SetBestClock(void);
int GetBestSensitivity(void);
int GetMaxFFTPowerFromRBW(double RBW);
int GetMinFFTPowerFromRBW(double RBW);
bool ForceFastSweep(double span, int swptmsetpt);
int CheckRBWVBW(void);
double m_lastCal9864Temp; //Variable for internal use only
public:
CSettings m_settings;
double * pDataMin;
double * pDataMax;
double m_channelBW;
double m_channelSpacing;
int m_BBSPSetpt;
int m_serialNumber;
double m_HzPerPt;
int m_traceSize;
int m_SubTraceSize;
};
Settings.h
#pragma once
#define MAX_FREQ 4.4e9
// Modes for Zero Span ( m_ZSMode )
#define HOUND_ZS_MODE_AMPLITUDE 0
#define HOUND_ZS_MODE_FREQUENCY 1
#define HOUND_ZS_MODE_PHASE 2
// Modes for Video Detector Min Max ( m_VDMMA )
#define HOUND_VDMMA_MIN_MAX 1
#define HOUND_VDMMA_MIN_ONLY 2
#define HOUND_VDMMA_MAX_ONLY 3
#define HOUND_VDMMA_AVERAGE_ONLY 4
// Modes for Video Detector Processing ( m_VDMode )
#define HOUND_PROCESS_AS_POWER 1
#define HOUND_PROCESS_AS_VOLTAGE 2
#define HOUND_PROCESS_AS_LOG 3
#define HOUND_PROCESS_BYPASSED 4
// Sweep Modes ( m_sweepMode )
#define HOUND_SWEEP_MODE_SLOW_SWEEP 0
#define HOUND_SWEEP_MODE_FAST_SWEEP 1
#define HOUND_SWEEP_MODE_RBW_5MHz 2
#define HOUND_SWEEP_MODE_ZERO_SPAN 3
#define HOUND_SWEEP_MODE_TRACK_GEN 5
#define HOUND_SWEEP_MODE_PHASE_NOISE 7
#define HOUND_SWEEP_MODE_BB_SIG_PEAK 9
// ZERO SPAN "IF Bandwidth" ( in m_RBWSetpoint ) when m_sweepMode = HOUND_SWEEP_MODE_ZERO_SPAN
#define HOUND_IFBW_240kHz 1
#define HOUND_IFBW_120kHz 2
#define HOUND_IFBW_60kHz 4
#define HOUND_IFBW_30kHz 8
#define HOUND_IFBW_15kHz 16
class CSettings
{
public:
CSettings(void);
~CSettings(void);
double m_startFreq; //Values in Hz. Start, stop, center and span must all be valid before beginning sweep
double m_stopFreq; // Use
double m_centerFreq;
double m_spanFreq;
double m_stepFreq; //Default 1 MHz step (IGNORED IN API)
double m_stepAmpl; //Amplitude step (IGNORED IN API)
double m_refLevel; //Ref level in dBm. Used to set gains
double m_refLevelOffset; // (IGNORED IN API)
int m_refUnitsmV; // (IGNORED IN API)
double m_logDbDiv; // (IGNORED IN API)
int m_attenIndex; // in 5 dB steps. 0 = 0dB, 3 = 15 dB
bool m_scaleLin; // (IGNORED IN API)
int m_AmplUnits; // (IGNORED IN API)
bool m_signalTrackOn; // (IGNORED IN API)
int m_vidAvg; // (IGNORED IN API)
bool m_TrigVideo; // Untested in API
double m_TrigPos; // 0 to 1, fraction of sweep time. Amplitude for TG sweep
int m_CalOutSyncTrig; // (IGNORED IN API)
double m_videoTriggerLevel;// Untested in API
int m_ZSMode; //Zero span / demod mode, 0=amplitude, 1=frequency, 2=phase
int m_RBWSetpoint; //Resolution bandwidth setpoint.
// Values from 2 to 24, representing 5 MHz to 0.1 Hz, respectively.
// An index of 14 = RBW of 100 Hz.
// See GetRBWFromIndex for other values.
int m_VBWSetpoint; //Same values as m_RBWSetpoint
int m_VDMMA; //Includes min/max/average
int m_VDMode; //Includes log/power/voltage modes
bool m_UseExtRef; // Untested in API
bool m_RBWIsAuto; // Set to allow software to choose best RBW.
bool m_VBWIsAuto; // Set to allow software to choose best VBW.
int m_SWPTMSetpoint; // Set from 0-4 meaning "fast" to "slow", as a suggested sweep speed
bool m_maxHold; // (IGNORED IN API)
bool m_suppressImage; // Image suppression on or off.
int m_decimation; // Automatically updated by API
int m_MarkerSelected; // (IGNORED IN API)
int m_sweepMode; // Selected mode for sweeping. See #defines
double m_sweepTime; // Not yet implemented in API
int m_Averaging; // Automatically updated by API
int m_DetectorPasses; // Automatically updated by API
int m_SubTraceCount; // Automatically updated by API
int m_FFTSize; // Automatically updated by API
int m_traceSize; // Automatically updated by API
double m_ExtMixerOffset; // (IGNORED IN API)
double m_ZSFreqPeak; // (IGNORED IN API)
double m_ZSSweepTime; // Set to control sweep time in zero span.
int m_SweepsToDo; // (IGNORED IN API)
int m_Overpowered; // Not yet implemented in API
int m_PreampOn; // Updated by CMySignalHound::PreamplifierOnOff
int m_PNStartDecade; // Not yet implemented in API
int m_PNStopDecade; // Not yet implemented in API
int m_iReserved1;
double m_dReserved1;
// //Calculate FFT size, decimation, RBW,VBW,etc.
void CalcSweepParams(void);
__declspec(dllimport) int GetBWIDX(double bw);
bool isEqual(CSettings * p1, CSettings * p2);
bool SetStartStop(double fStart, double fStop);
};
而主程式只是想要產生一個Reference如下:
#include <vcl.h>
#pragma comment(lib,"HeadlessAPIWin32.dll")
#include <tchar.h>
//#pragma comment()
#pragma link "UNIT1.OBJ"
#pragma hdrstop
#include "MySignalHound.h"
#include "windows.h"
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
CMySignalHound myHound;
system("pause");
return 0;
}
錯誤訊息如下:
[Linker Error]Unresolved External CMySignalHound::~CMSignalHound() referenced from c:\users\unit1.obj
[Linker][Linker Error]Unresolved External CMySignalHound::CMSignalHound() referenced from c:\users\unit1.obj
[Linker Error]Unresolved External CSettins::~CSettings() referenced from c:\users\unit1.obj
希望有經驗大大給予我一些意見
uj5u.com熱心網友回復:
對于C++而言,Visual C++和Borland C++/C++Builder采用不同的Name Mangling,因此Borland C++/C++Builder基本上不能使用Visual C++編譯的DLL中的類(class)。如果一定要用可以想辦法將類平板化,即將類的方法包裝成一個個獨立的C函式,再將這些C函式用Visual C++編譯成另一個DLL(helper DLL),然后用implib等工具。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/145985.html
