这篇教程C++ sprintf_s函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中sprintf_s函数的典型用法代码示例。如果您正苦于以下问题:C++ sprintf_s函数的具体用法?C++ sprintf_s怎么用?C++ sprintf_s使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了sprintf_s函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: sprintf_sBOOL GameObject::GetObjStat ( char * sStr, int iLen ){ sprintf_s (sStr, iLen, "Obj type /'%s/'/nObj name /'%s/'/nPOS /'[%f,%f,%f]/'/n", Class->Name.c_str (), Name.c_str(),GetPosition().x,GetPosition().y,GetPosition().z); return TRUE;}
开发者ID:Mateuus,项目名称:srcundead,代码行数:5,
示例2: GetModuleFileNameADWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize){#if defined(__linux__) int status; int length; char path[64]; if (!hModule) { char buffer[4096]; sprintf_s(path, ARRAYSIZE(path), "/proc/%d/exe", getpid()); status = readlink(path, buffer, sizeof(buffer)); if (status < 0) { SetLastError(ERROR_INTERNAL_ERROR); return 0; } buffer[status] = '/0'; length = strlen(buffer); if (length < nSize) { CopyMemory(lpFilename, buffer, length); lpFilename[length] = '/0'; return length; } CopyMemory(lpFilename, buffer, nSize - 1); lpFilename[nSize - 1] = '/0'; SetLastError(ERROR_INSUFFICIENT_BUFFER); return nSize; }#elif defined(__MACOSX__) int status; int length; if (!hModule) { char path[4096]; char buffer[4096]; uint32_t size = sizeof(path); status = _NSGetExecutablePath(path, &size); if (status != 0) { /* path too small */ SetLastError(ERROR_INTERNAL_ERROR); return 0; } /* * _NSGetExecutablePath may not return the canonical path, * so use realpath to find the absolute, canonical path. */ realpath(path, buffer); length = strlen(buffer); if (length < nSize) { CopyMemory(lpFilename, buffer, length); lpFilename[length] = '/0'; return length; } CopyMemory(lpFilename, buffer, nSize - 1); lpFilename[nSize - 1] = '/0'; SetLastError(ERROR_INSUFFICIENT_BUFFER); return nSize; }#endif WLog_ERR(TAG, "%s is not implemented", __FUNCTION__); SetLastError(ERROR_CALL_NOT_IMPLEMENTED); return 0;}
开发者ID:Devolutions,项目名称:FreeRDP,代码行数:78,
示例3: EnumDisplayModesDWORD EnumDisplayModes(int config_width, int config_height, int config_bpp, bool config_windowed, DisplayModeList& list) { list.clear(); LPDIRECT3D9 d3d = Direct3DCreate9(D3D_SDK_VERSION); CONFIRM(d3d) else return -1; D3DDISPLAYMODE d3ddm_current; d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm_current); DWORD current_mode = -1, config_mode = -1, best_windowed_mode = -1; typedef std::set<std::pair<int,int>> WindowedModes; WindowedModes windowed_modes; static const D3DFORMAT ALLOWED_FORMATS[] = { D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_R8G8B8, D3DFMT_X8R8G8B8 }; static const int ALLOWED_FORMAT_BPP[] = { 15, 16, 24, 32 }; static const int ALLOWED_FORMAT_COUNT = 4; for (int format = 0; format < ALLOWED_FORMAT_COUNT; ++format) { DWORD modes = d3d->GetAdapterModeCount(D3DADAPTER_DEFAULT, ALLOWED_FORMATS[format]); DWORD best_windowed_mode_area = 0; DisplayMode dm; dm.bpp = ALLOWED_FORMAT_BPP[format]; for (DWORD i =0; i < modes; ++i) { D3DDISPLAYMODE d3ddm; d3d->EnumAdapterModes(D3DADAPTER_DEFAULT, ALLOWED_FORMATS[format], i, &d3ddm); if (d3ddm.Width < 800 || d3ddm.Height < 600) continue; // throw out low resolutions dm.width = d3ddm.Width; dm.height = d3ddm.Height; { // kick out ridiculously widescreen formats const float aspect_ratio = (float)d3ddm.Width / (float)d3ddm.Height; if (aspect_ratio > 2.0f) continue; } if (d3ddm_current.Width == d3ddm.Width && d3ddm_current.Height == d3ddm.Height && d3ddm_current.Format == d3ddm.Format) { current_mode = list.size(); } if (config_width == dm.width && config_height == dm.height && config_bpp == dm.bpp && config_windowed == false) { config_mode = list.size(); } char text[256]; dm.windowed = false; sprintf_s(text, 256, "fullscreen : %i x %i (%i-bit color)", dm.width, dm.height, dm.bpp); dm.text = text; list.push_back(dm); DWORD area = dm.width * dm.height; WindowedModes::value_type wm_value(dm.width, dm.height); if (area <= (1280*1024) && // only add lower resolutions as windowed modes windowed_modes.find(wm_value) == windowed_modes.end()) { // prevent duplication windowed_modes.insert(wm_value); dm.windowed = true; sprintf_s(text, 256, "windowed : %i x %i", dm.width, dm.height); dm.text = text; if (best_windowed_mode_area < area) { best_windowed_mode = list.size(); } if (config_width == dm.width && config_height == dm.height && config_windowed == true) { config_mode = list.size(); } list.push_back(dm); } } } d3d->Release(); if (config_mode < list.size()) return config_mode; if (current_mode < list.size()) return current_mode; return best_windowed_mode;}
开发者ID:karlgluck,项目名称:evidyon-2.10,代码行数:85,
示例4: sprintf_svoid CZQIniFile::WriteInteger(char* szSection, char* szKey, int iValue){ char szValue[255]; sprintf_s(szValue, 255,"%d", iValue); WritePrivateProfileString((LPCSTR)szSection, (LPCSTR)szKey, (LPCSTR)szValue, (LPCSTR)m_szFileName);}
开发者ID:mikesimb,项目名称:Lander,代码行数:6,
示例5: sprintf_s//// Update Headpose in Game.//void FTNoIR_Protocol::sendHeadposeToGame( THeadPoseData *headpose, THeadPoseData *rawheadpose ) {int no_bytes;QHostAddress sender;quint16 senderPort;PDWORD_PTR MsgResult = 0;#ifdef SEND_ASCII_DATAchar data[100];#endif // // Copy the Raw measurements directly to the client. // FlightData.x = headpose->x; FlightData.y = headpose->y; FlightData.z = headpose->z; FlightData.p = headpose->pitch; FlightData.h = headpose->yaw; FlightData.r = headpose->roll; FlightData.status = fg_cmd; // // Try to send an UDP-message to the FlightGear //#ifdef SEND_ASCII_DATA sprintf_s(data, "%.2f %.2f %.2f %.2f %.2f %.2f/n/0", FlightData.x, FlightData.y, FlightData.z, FlightData.p, FlightData.h, FlightData.r); if (outSocket != 0) { no_bytes = outSocket->writeDatagram((const char *) &data, strlen( data ), destIP, destPort); if ( no_bytes > 0) { qDebug() << "FGServer::writePendingDatagrams says: bytes send =" << data; } else { qDebug() << "FGServer::writePendingDatagrams says: nothing sent!"; } }#endif #ifdef LOG_OUTPUT // Use this for some debug-output to file... QFile datafile(QCoreApplication::applicationDirPath() + "//FG_output.txt"); if (datafile.open(QFile::WriteOnly | QFile::Append)) { QTextStream out(&datafile); out << "output:/t" << FlightData.x << "/t" << FlightData.y << "/t" << FlightData.z << "/t" << FlightData.p << "/t" << FlightData.h << "/t" << FlightData.r << '/n'; } #endif #ifndef SEND_ASCII_DATA //! [1]// no_bytes = outSocket->writeDatagram((const char *) &FlightData, sizeof( FlightData ), QHostAddress::LocalHost, 5550); if (outSocket != 0) { no_bytes = outSocket->writeDatagram((const char *) &FlightData, sizeof( FlightData ), destIP, destPort); if ( no_bytes > 0) { // qDebug() << "FGServer::writePendingDatagrams says: bytes send =" << no_bytes << sizeof( double ); } else { qDebug() << "FGServer::writePendingDatagrams says: nothing sent!"; } } #endif // // FlightGear keeps sending data, so we must read that here. // if (inSocket != 0) { while (inSocket->hasPendingDatagrams()) { QByteArray datagram; datagram.resize(inSocket->pendingDatagramSize()); inSocket->readDatagram( (char * ) &cmd, sizeof(cmd), &sender, &senderPort); fg_cmd = cmd; // Let's just accept that command for now... if ( cmd > 0 ) { qDebug() << "FGServer::sendHeadposeToGame hasPendingDatagrams, cmd = " << cmd;// headTracker->handleGameCommand ( cmd ); // Send it upstream, for the Tracker to handle } if (!blnConnectionActive) { blnConnectionActive = true; if (hMainWindow != NULL) { SendMessageTimeout( (HWND) hMainWindow, RegisterWindowMessageA(FT_PROGRAMID), 0, 0, 0, 2000, MsgResult); } } } }}
开发者ID:kineticgar,项目名称:facetracknoir,代码行数:92,
示例6: SetupHooksvoid SetupHooks() { logInfo("Setting up hooks."); if(hooksSetup) return; HMODULE d3dMod = GetModuleHandle("d3d9.dll"); if(d3dMod == NULL) { ErrorMsg("GetModuleHandle(d3d9.dll)"); return; } HMODULE d3dxMod = LoadLibrary("d3dx9_43.dll"); if(d3dxMod == NULL) { ErrorMsg("LoadLibrary(d3dx9_43.dll)"); return; } HMODULE winmmMod = LoadLibrary("winmm.dll"); if(winmmMod == NULL) { ErrorMsg("LoadLibrary(winmm.dll)"); return; } D3DCreate = (pDirect3DCreate9)GetProcAddress(d3dMod, "Direct3DCreate9"); if(D3DCreate == NULL) { ErrorMsg("GetProcAddress(d3dMod, /"Direct3DCreate9/")"); return; } oPlaySound = (pPlaySoundA)GetProcAddress(winmmMod, "PlaySoundA"); if(oPlaySound == NULL) { ErrorMsg("GetProcAddress(winmmMod, /"PlaySoundA/")"); return; } oD3DXCreateFont = (pD3DXCreateFont)GetProcAddress(d3dxMod, "D3DXCreateFontA"); if(oD3DXCreateFont == NULL) { ErrorMsg("GetProcAddress(d3dxMod, /"D3DXCreateFontA/")"); return; } oD3DXCreateLine = (pD3DXCreateLine)GetProcAddress(d3dxMod, "D3DXCreateLine"); if(oD3DXCreateLine == NULL) { ErrorMsg("GetProcAddress(d3dxMod, /"D3DXCreateLine/")"); return; } // Create a dummy window to call CreateDevice on HWND hwnd; hwnd = CreateWindow("BUTTON", "APMAlertDummyWindow", 0, 0, 0, 27, 27, NULL, NULL, hInstance, NULL); if(hwnd == NULL) { ErrorMsg("CreateWindow"); return; } //UpdateWindow(hwnd); IDirect3D9 *pD3D = D3DCreate(D3D_SDK_VERSION); if(pD3D == NULL) { ErrorMsg("Direct3DCreate9"); return; } D3DDISPLAYMODE d3ddm; HRESULT hRes = pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm); if(FAILED(hRes)) { char errorMsg[512]; const char * dxErrorStr = DXGetErrorString(hRes); sprintf_s(errorMsg, 512, "GetAdapterDisplayMode returned 0x%08x: %s", hRes, dxErrorStr); logError(errorMsg); goto cleanup; } D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp)); d3dpp.Windowed = true; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; IDirect3DDevice9 * ppD3DDevice; hRes = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_DISABLE_DRIVER_MANAGEMENT, &d3dpp, &ppD3DDevice); if(FAILED(hRes)) { char errorMsg[512]; const char * dxErrorStr = DXGetErrorString(hRes); sprintf_s(errorMsg, 512, "CreateDevice returned 0x%08x: %s", hRes, dxErrorStr); logError(errorMsg); goto cleanup; } // Get our function pointers from the virtual table // This pointer dereferencing works because the virtual table is the first item in memory // of the every object void ** vTable = *((void***)ppD3DDevice); // Access the function pointers we need addrEndScene = vTable[42]; // EndScene is the 43rd function (you can just count in the interface decl in the header) /* char path_d3d9_dll[MAX_PATH]; GetSystemDirectory(path_d3d9_dll, MAX_PATH); strncat_s(path_d3d9_dll, MAX_PATH, "//d3d9.dll", 10); SIZE_T offset = (unsigned int)addrEndScene - (unsigned int)GetModuleHandle(path_d3d9_dll); printf("EndScene() Addr: 0x%08x -- SC2.exe!d3d9.dll+0x%x/n", addrEndScene, offset); *///.........这里部分代码省略.........
开发者ID:DARKLORD99999,项目名称:APMAlert2,代码行数:101,
示例7: LOGWARNINGtUInt32 DAXAudio::WriteSound(string host,tUInt32 port,tByte* data,tUInt32 size){ if (!_player) return 0;#ifdef SPEEX_CODE tByte frame[BLOCK_SIZE]={0}; int voicesize = *((tUInt32*)(data)); int timestamp = *((tUInt32*)(data+4)); if (timestamp % FRAME_SIZE != 0) { LOGWARNING("DAXAudio::WriteSound:Currupted data with timestamp "<<timestamp<<" from "<<host<<"::"<<port<<",abandon the data!"); return 0; } if (voicesize!=size-8) { LOGWARNING("DAXAudio::WriteSound:Currupted data from "<<host<<" for "<<voicesize<<"!="<<size<<"-8,abandon the data!"); return 0; }#ifdef USING_JITTER // find the right jitter and stored the data into // check if player can playmore,if yes, get a frame from all jitters and merge them // write the merged data into player. tByte from[100]={0}; sprintf_s((char*)from,100,"%s::%u",host.c_str(),port); tFromJitterMapIter iter = _from_jitter_map.find(from); if (iter==_from_jitter_map.end()) { LOGWARNING("DAXAudio::WriteSound:From "<<from<<" is not registered,abandon the data!"); return 0; } speex_jitter_put(iter->second,(char*)(data+8),size-8,timestamp); if (_player->ReadyForPlayMore()) { GetMergedFramFromJitters(frame,BLOCK_SIZE); _player->WriteSound(frame,BLOCK_SIZE); return size; } else { LOGWARNING("DAXAudio::WriteSound:Player is busy,wait a momment..."); return 0; }#else if (_converter->Decode(data+8,size-8,frame,BLOCK_SIZE)) if(_player->WriteSound(frame,BLOCK_SIZE)) return size; return 0;#endif //USING_JITTER#else // just for test, of course coded and sent. //if (_player->ReadyForPlayMore()) return _player->WriteSound(data,size); //else // return 0;#endif //SPEEX_CODE}
开发者ID:BGCX261,项目名称:zombie3-svn-to-git,代码行数:64,
示例8: getVacantClubvoid oEvent::generatePreReport(gdioutput &gdi){ CurrentSortOrder=SortByName; Runners.sort(); int lVacId = getVacantClub(); oRunnerList::iterator r_it; oTeamList::iterator t_it; //BIB, START, NAME, CLUB, RANK, SI int dx[6]={0, 0, 70, 300, 470, 470}; bool withrank = hasRank(); bool withbib = hasBib(true, true); int i; if (withrank) dx[5]+=50; if (withbib) for(i=1;i<6;i++) dx[i]+=40; int y=gdi.getCY(); int x=gdi.getCX(); int lh=gdi.getLineHeight(); gdi.addStringUT(2, lang.tl("Rapport inf C++ sprintf_safe函数代码示例 C++ sprintf_P函数代码示例
|