問題1.: fatal error C1083: 無法打開包含文件:“iostream.h”: No such file or directory
解決辦法:
將 #include "iostream.h" //(vc++6.0)
替換為: //(vc++7.0 /vc++.net)
#include "IOSTREAM" // 包含流的舊式頭文件 //使用舊的iostream頭文件不要加.h
using namespace std; //另需添加部分
PLCHandler.obj : error LNK2001: unresolved external symbol "public: bool __thiscall PLCDB90::read(long,long,long * const)" (?read@PLCDB90@@QAE_NJJQAJ@Z)
PLCHandler.obj : error LNK2001: unresolved external symbol "public: bool __thiscall PLCDB80::read(long,long,long * const)" (?read@PLCDB80@@QAE_NJJQAJ@Z)
bin/PlcOperation.exe : fatal error LNK1120: 2 unresolved externals
在plcdb90.cpp文件中沒有對其實現(xiàn)
PLCDB90::read(long,long,long * const)
2*****************
問題:
--------------------Configuration: DataTrans - Win32 Debug--------------------
Compiling
DataTrans.cpp
D:\VC60Projects\DataTrans\DataTrans.cpp(22) : error C2065: 'cout' : undeclared identifier
D:\VC60Projects\DataTrans\DataTrans.cpp(22) : error C2297: '<<' : illegal, right operand has type 'char [4]'
D:\VC60Projects\DataTrans\DataTrans.cpp(22) : error C2065: 'endl' : undeclared identifier
D:\VC60Projects\DataTrans\DataTrans.cpp(23) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
PLCHandler.cpp
DataHelper.cpp
Generating Code
Error executing cl.exe.
DataTrans.exe - 3 error(s), 1 warning(s)
//****************************************************
解決:
在project setting里面的 c/c++ 選項卡
在combo里面找到 precompiled header
選擇 no precompiled header 即可
3***********************
bool bflag型
bool 應(yīng)大寫為 BOOL
4***********************
c1.h,c2.h 頭文件的互相包含
c1.h中寫上#include "c2.h",class c2;
c2.h中同樣如此.
5*******************************
d:\shengwuproject\0911\dbcallback.cpp(15) : error C2371: 'public: static class PLC * cTestCallBack::pLCDB902' : redefinition; different basic types
d:\shengwuproject\0911\dbcallback.h(34) : see declaration of 'public: static class PLC * cTestCallBack::pLCDB902'
PLC *cTestCallBack::pLCDB902; //靜態(tài)變量聲明
前面聲明的類型plc和后面的*cTestCallBack::pLCDB902 變量類型plcdb90不一樣.
6=============================
已經(jīng)包含了#include <process.h>頭文件,編譯時仍然說'_beginthread' undeclared identifier
解決:
根據(jù)下列步驟進行設(shè)置.
project->settings->c/c++:
Category:Code Generation
Use run-time library:
debug version:
Debug Multithread DLL
release version:
Multithread DLL
7==============================
問題:
PLCDB90.obj : error LNK2001: unresolved external symbol "class ATL::CComModule _Module" (?_Module@@3VCComModule@ATL@@A)
bin/PlcOperation.exe : fatal error LNK1120: 1 unresolved externals
解決:
添加ATL頭文件
使用ATL前必須包含以下頭文件:atlbase.h和atlcom.h,并且定義_Module變量[2]。把以下代碼加到stdafx.h是最方便的:
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
在cpp文件中要對_Module進行定義。如下:
CcomModule _Module;
在添加了這兩行之后,我們就可以使用ATL的功能了。而不必創(chuàng)建ATL的項目。
當(dāng)然,如果項目是通過ATL項目向?qū)Мa(chǎn)生的就不必再次添加頭文件了。
http://www.jr163.org/cup2/18/18781.htm
8===================================
問題:
在MFC(界面)下調(diào)用PLC com組件,能響應(yīng)Com回調(diào)dataChange事件,在控制臺程序則不能.
原因:
因為COM利用消息機制來實現(xiàn)STA,因此STA套間里的線程必須實現(xiàn)消息循環(huán),否則COM將不能實現(xiàn)STA的要求。
解決:
在程序中加入:
#include <windows.h>
// Main message loop:
MSG msg;
while/if(GetMessage(&msg, NULL, 0, 0))
{
// TranslateMessage(&msg);
DispatchMessage(&msg);
}