看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《jeep168917 (幫幫)》之銘言: : 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) : VC++ : 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) : 問題(Question): : 不太清楚為什麼會出現CreateFileMappingW,錯誤特別是還多了"W" : error2和3也很奇怪,不知道是哪裡出了問題 : 餵入的資料(Input): : 預期的正確結果(Expected Output): : 錯誤結果(Wrong Output): : Error1 error C2664: 'CreateFileMappingW' : cannot convert parameter 6 from : 'char [14]' to 'LPCWSTR' : Error2 error C2146: syntax error : missing ')' before identifier '_DATE_' : Error3 error C2059: syntax error : ')' : 程式碼(Code):(請善用置底文網頁, 記得排版) : // 23d.cpp : Defines the entry point for the console application. : // : #include "stdafx.h" : #include "23d.h" : #include "stdlib.h" : #include "windows.h" : #include "stdio.h" : #define SHAREMEM_NAME "c:shareMemory" : #define BULID_MESSAGE "Today is"_DATE_" "_TIME_ : #ifdef _DEBUG : #define new DEBUG_NEW : #endif : // The one and only application object : CWinApp theApp; : using namespace std; : int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) : { : int nRetCode = 0; : /// : LPCTSTR pBuf; : HANDLE hFile; : int i; : char szFileName[]=SHAREMEM_NAME; : char writeBuffer[128]={0}; : //宣告變數 : //建立共用記憶體 : hFile=CreateFileMapping( : (HANDLE)0xFFFFFFFF, : //表示內存中開闢一個區塊 : NULL, : PAGE_READWRITE, : //讀取在一個區塊 : 0, : sizeof(writeBuffer), : //代表一個內存中的二進制數據區塊正在累計讀入 : szFileName : ); : //建立一個大小為1024bytes的分享記憶體 : //得到映射(位址)的記憶體 : pBuf=(LPCTSTR)MapViewOfFile( : hFile, : FILE_MAP_ALL_ACCESS, : 0, : 0, : sizeof(writeBuffer) : ); : //放入自己的位址空間 : //創造新的連結並顯示 : strcat((char*)pBuf,BULID_MESSAGE "\n"); : while(1){ : printf("%s\n",pBuf); : Sleep(1000); : } : CloseHandle(hFile); : } : 補充說明(Supplement): : 最近正在研究shared memory,我是新手,若有違反版規,我願意刪文,感恩! 已更正"專案設定->character set->Multi-byte",寬字元字集與單字元字集的問題。 但是跑去更多的error,似乎不是我原本程式碼的關係,error如下: warning C4244:'=' : conversion from 'const WCHAR' to 'TCHAR', possible loss of data warning C4244:'=' : conversion from 'const WCHAR' to 'TCHAR', possible loss of data warning C4244:'=' : conversion from 'const WCHAR' to 'TCHAR', possible loss of data error C2664:'ATL::CStringT<BaseType,StringTraits>::CStringT(const VARIANT &)' : cannot convert parameter 1 from 'LPCTSTR' to 'const VARIANT &' error C2664:'strftime' : cannot convert parameter 3 from 'LPCTSTR' to 'const char *' error C2664:'ATL::CStringT<BaseType,StringTraits>::CStringT(const VARIANT &)' : cannot convert parameter 1 from 'LPCTSTR' to 'const VARIANT &' error C2664:'strftime' : cannot convert parameter 3 from 'LPCTSTR' to 'const char *' error C2664:'GetModuleHandleW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR' error C2664:'LoadLibraryW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR' error C2535:'void CCommandLineInfo::ParseParam(const TCHAR *,BOOL,BOOL)' : member function already defined or declared error C2535:'void CCommandLineInfo::ParseParamNotFlag(const TCHAR *)' : member function already defined or declared error C2440:'initializing' : cannot convert from 'char *' to 'LPTSTR' error C2440:'=' : cannot convert from 'char *' to 'LPTSTR' warning C4244:'return' : conversion from 'WCHAR' to 'TCHAR', possible loss of data error C2446:':' : no conversion from 'LPCTSTR' to 'const char *' error C2664:'CString ATL::COleDateTimeSpan::Format(LPCTSTR) const' : cannot convert parameter 1 from 'CString' to 'LPCTSTR' -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.24.116