调用CreateFile失败了为什么 [问题点数:50分,结帖人youxi3505]

Bbs1
本版专家分:0
结帖率 98.73%
Bbs1
本版专家分:0
Bbs1
本版专家分:0
Bbs3
本版专家分:830
简单驱动,在用户态调用CreateFile()时失败
最近在尝试自己写个驱动程序,但是在用户态<em>调用</em>CreateFile()时总是<em>失败</em>,返回0xffffffff,请各路高手帮我找找问题所在,谢谢了。 rnrn// 驱动代码代码如下 rnrnrnC/C++ codern//rn// HelloWorldDrv.crn//rn#include "ntstatus.h"rn#include "ntddk.h"rn#include rn#include rn#define true 1rn#define false 0rn// const variablesrnconst WCHAR deviceNameBuffer [] = L"\\Device\\HelloWorldDevice";rnconst WCHAR dosDeviceNameBuffer [] = L"\\DosDevice\\HelloWorldDevice";rn// global pointer to our device objectrnPDEVICE_OBJECT g_helloWorldDevice;rn// This is our unload functionrnvoid OnUnload ( IN PDRIVER_OBJECT driverObject )rnrn UNICODE_STRING strDosDeviceNameUnicodeString;rn DbgPrint ( "OnUnload() called!!!!!!\n" );rn RtlInitUnicodeString ( &strDosDeviceNameUnicodeString, dosDeviceNameBuffer );rn // delete symbolic linkrn IoDeleteSymbolicLink ( &strDosDeviceNameUnicodeString );rn // delete device rn IoDeleteDevice ( driverObject->DeviceObject );rnrnrnNTSTATUS MyOpen ( IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIRP )rnrn DbgPrint ( "MyOpen() called!!!\n" );rn return STATUS_SUCCESS;rn rnrnNTSTATUS MyClose ( IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIRP )rnrn DbgPrint ( "MyClose() called!!!\n" );rn return STATUS_SUCCESS;rnrnrnNTSTATUS MyRead ( IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIRP )rnrn NTSTATUS ntStatus = STATUS_SUCCESS; rn DbgPrint ( "MyRead() called!!!!!!\n" ); rn return ntStatus;rnrnrnNTSTATUS MyWrite ( IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIRP )rnrn NTSTATUS ntStatus = STATUS_SUCCESS; rn DbgPrint ( "MyWrite() called!!!!!!\n" ); rn return ntStatus;rnrnrn// Entry functionrnNTSTATUS DriverEntry ( IN PDRIVER_OBJECT pDriverObject, rn IN PUNICODE_STRING theRegistryPath )rnrn //NTSTATUS ntStatus;rn UNICODE_STRING strDeviceNameUnicodeString;rn UNICODE_STRING strDosDeviceNameUnicodeString;rn NTSTATUS ntStatus;rn rn DbgPrint ( "DriverEntry() called!!!!!!\n" );rn rn // set up our namern RtlInitUnicodeString ( &strDeviceNameUnicodeString, deviceNameBuffer );rn RtlInitUnicodeString ( &strDosDeviceNameUnicodeString, dosDeviceNameBuffer ); rn // Initialize the pointer to the unload function in the driverObjectrn pDriverObject->DriverUnload = OnUnload; rn // set functionsrn pDriverObject->MajorFunction [ IRP_MJ_CREATE ] = MyOpen;rn pDriverObject->MajorFunction [ IRP_MJ_CLOSE ] = MyClose;rn pDriverObject->MajorFunction [ IRP_MJ_READ ] = MyRead;rn pDriverObject->MajorFunction [ IRP_MJ_WRITE ] = MyWrite; rn // create device rn ntStatus = IoCreateDevice ( pDriverObject, 0,// for driver extension &strDeviceNameUnicodeString, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, false,rn &g_helloWorldDevice ); rn if ( NT_SUCCESS( ntStatus ) )rn rn // create a symbolic link to the devicern IoCreateSymbolicLink ( & strDosDeviceNameUnicodeString, strDeviceNameUnicodeString );rn rn return STATUS_SUCCESS;rnrnrnrn//rn// SOURCESrn//rnTARGETNAME=HelloWorldDrvrnTARGETPATH=OBJrnTARGETTYPE=DRIVERrnSOURCES=HelloWorldDrv.crnrnrn//rn// MAKEFILErn//rn!INCLUDE $(NTMAKEENV)\makefile.defrnrnrn//rn// HelloWorldApp.crn//rn#include rn#include rnrnint main()rnrnrn HANDLE hFile;rn DWORD dwReturn;rnrn hFile = CreateFile("\\\\.\\HelloWorldDevice", rn GENERIC_WRITE, rn 0, rn NULL, rn OPEN_EXISTING, rn FILE_ATTRIBUTE_NORMAL,rn NULL);rnrn if( hFile == INVALID_HANDLE_VALUE )rn rn printf("create file failed!!!\n");rn rn elsern rn CloseHandle(hFile);rn rn return 0;rnrnrnrn
createfile和copyfile都失败啊,为什么
[code=c]#include rn#include rn#define BUF_SIZE 256rnint main(int argc,LPTSTR argv[])rnrn /*HANDLE hIn,hOut;rn DWORD nIn,nOut;rn CHAR buff[BUF_SIZE];rn if (argc!=3)rn rn printf("参数错误\n");rn rn hIn = CreateFile(argv[1],GENERIC_READ,FILE_SHARE_READ,NULL,rn OPEN_EXISTING,NULL,NULL);rn if (hIn == INVALID_HANDLE_VALUE)rn rn printf("%s打开<em>失败</em> error:%x\n",argv[1],GetLastError);rn rn hOut = CreateFile(argv[2],GENERIC_WRITE,FILE_SHARE_WRITE,NULL,rn CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);rn if (hOut == INVALID_HANDLE_VALUE)rn rn printf("创建<em>失败</em> error:%x\n",GetLastError);rn rn while (ReadFile(hIn,buff,BUF_SIZE,&nIn,NULL)&&nIn>0)rn rn WriteFile(hOut,buff,nIn,&nOut,NULL);rn if (nIn!=nOut)rn rn printf("文件读写错误:%x\n",GetLastError());rn return 4;rn rn rn CloseHandle(hIn);rn CloseHandle(hOut);rn */rn if (!CopyFile(argv[1],argv[2],FALSE))rn rn printf("复制出错 error:%x\n",GetLastError);rn return 2;rn rn return 0;rn[/code]rn刚开始学win系统编程,代码如上,就是简单的复制个文件rngetlasterror值是768a11c0
为什么流接口驱动CreateFile失败呢?
HANDLE handle=CreateFile(_T("TTT1:"),GENERIC_READ|GENERIC_WRITE,0,rnNULL,OPEN_EXISTING,0,NULL);rnASSERT(handle);rnif (handle == INVALID_HANDLE_VALUE) // cannot open the drivernrn MessageBox(NULL,_T("CreateFile<em>失败</em>"),_T("title"),MB_OK);rnrn这<em>为什么</em>呢?
CreateFile 的调用
Private Type SECURITY_ATTRIBUTES rn nLength As Long rn lpSecurityDescriptor As Long rn bInheritHandle As Boolean rnEnd Type rnPrivate Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long rnPrivate Declare Function GetLastError Lib "kernel32" () As Long rnPrivate Sub Form_Load() rnDim MyLP As SECURITY_ATTRIBUTES rnMyLP.nLength = Len(MyLP) rnMyLP.lpSecurityDescriptor = 0 rnMyLP.bInheritHandle = False rnhfile = CreateFile("d:\test.txt", GENERIC_READ, FILE_SHARE_READ, MyLP, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, ByVal 0&) rnMsgBox hfile rnMsgBox GetLastError rnEnd Sub rn rn以上是我的代码,我的系统是xp的,用的是vb6,<em>为什么</em>GetLastError返回值总是 -1?
CreateFile创建文件失败??????????-〉help
新建一个Dialog程序rn在OnInitDialog()中添加rnrn HANDLE hFile;rn hFile = CreateFile("C:\tradex.txt",rn GENERIC_WRITE,rn FILE_SHARE_READ,rn NULL,rn CREATE_ALWAYS, rn FILE_ATTRIBUTE_NORMAL,rn NULL); rn if (hFile == INVALID_HANDLE_VALUE)rn rn MessageBox("Create file error!",NULL,MB_OK);rn return 0;rn rnrn编译没错,就是运行的时候出一框:Create file error!
createfile打开失败的问题??
#include rnrn#define _WIN32_WINNT 0x0500rn#include rnrnrnint main(int argc, char *argv[])rnrnrn HANDLE hDirectory = CreateFile("D:\\", GENERIC_ALL, FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, NULLrn , OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);rn rn if (INVALID_HANDLE_VALUE == hDirectory) [color=#FF0000] //现在是在这里出了鬼,老是无效句柄[/color]rn rn cout << "create file failed!" << endl;rn DWORD dwErr = GetLastError();rn return -1;rn rn rn while (TRUE)rn rn Sleep(1000);rnrn FILE_NOTIFY_INFORMATION stFileNotifyInfo = 0;rn DWORD dwBytesRet = 0;rnrn BOOL bRet = ReadDirectoryChangesW(rn hDirectory,rn &stFileNotifyInfo,rn sizeof (FILE_NOTIFY_INFORMATION),rn TRUE,rn FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME|FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_SIZE|FILE_NOTIFY_CHANGE_LAST_WRITE|FILE_NOTIFY_CHANGE_LAST_ACCESS|FILE_NOTIFY_CHANGE_CREATION|FILE_NOTIFY_CHANGE_SECURITY, rn &dwBytesRet,rn NULL,rn NULLrn );rn rn if (bRet)rn rn cout << "change occour!" << endl;rn rn rnrn CloseHandle(hDirectory);rnrn return 0;rnrnrn我想写个文件监控程序,我首先要用<em>createfile</em>打开一个文件,得到handle,然后再ReadDirectoryChangesW,传递这个handle进去,但是我现在<em>createfile</em>打开directory死活成功不了,错误号老是3,无法识别路径,出了鬼了,请各位帮忙看看,谢谢了.
CreateFile失败 GetLastError=2
[code=Delphi(Pascal)]rn#include rn#include rnrnvoid main()rnrn HANDLE handle=CreateFile("D:\\E.EXE", rn GENERIC_READ, rn FILE_SHARE_READ, rn NULL, rn OPEN_EXISTING, rn FILE_ATTRIBUTE_NORMAL, rn 0);rn if ( handle==INVALID_HANDLE_VALUE )rn rn printf( "%d",GetLastError() );rn return;rn rnrn[/code]
CreateFile创建串口失败
   HCom1ConnWithLcd = CreateFile(&quot;(LPCWSTR)COM1:&quot;,//COM1 GENERIC_READ|GENERIC_WRITE, //允许读和写 0, //独占方式 NULL, OPEN_EXISTING, //打开而不是创建 0, //同步方式 NULL);...
CreateFile串口打开失败
static Handle hCom = NULL;rnhCom = CreateFile((LPCWSTR)"COM1", GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); rnif(INVALID_HANDLE_VALUE == hCom) rn rn INT err = GetLastError();//<em>为什么</em>每次都跑到这里来呢,err==2!!!!!!
Windows 7下CreateFile()失败
我在Windows XP下<em>调用</em>如下代码没有问题,可在Windows 7下<em>失败</em>,GetLastError()返回2.rnrn清高手们帮忙解释一下啊.rnrn我用超级管理员的身份登陆Windows运行也是<em>失败</em>rnrnhDevice = CreateFile("\\\\.\\Ezusb-0",rn GENERIC_WRITE,rn FILE_SHARE_WRITE,rn NULL,rn OPEN_EXISTING,rn 0,rn 0);rnrn int error = GetLastError();rnrn if (hDevice == INVALID_HANDLE_VALUE) rn hDevice = CreateFile("\\\\.\\Ezusb-1",rn GENERIC_WRITE,rn FILE_SHARE_WRITE,rn NULL,rn OPEN_EXISTING,rn 0,rn 0);rnrn error = GetLastError();rnrn if (hDevice == INVALID_HANDLE_VALUE)rn return false;rn elsern return true;rn rn elsern return true;
关于CreateFile失败
Windows mobile 6 (vs2005)用CreateFile连续新建很多个文件,用模拟器来测试,共享pc机上的目录来模拟一个Storage Card目录rn hFile = CreateFile(lpFolder,rn GENERIC_READ|GENERIC_WRITE,rn FILE_SHARE_READ|FILE_SHARE_WRITE,rn NULL,rn CREATE_ALWAYS,rn FILE_ATTRIBUTE_NORMAL,rn NULLrn );rn如果我的lpFolder不是建在//Storage Card,就没问题。但如果是,CreateFile会在循环建立文件到某一次时<em>失败</em>,请问这是怎么回事?
CreateFile操作命名管道失败
服务器代码:rn[code=c]rn#include rn#include rnrnint main()rnrn HANDLE hpip;rn OVERLAPPED ovi = 0;rn char buff[200];rn DWORD readbuf;rn hpip = CreateNamedPipe( TEXT("\\\\.\\pipe\\pipename"), PIPE_ACCESS_DUPLEX,rn PIPE_TYPE_BYTE, PIPE_UNLIMITED_INSTANCES, 1024, 1024, 0, NULL );rn printf( "success to create named pipe, waiting for client to connect. \r\n" );rn if( ::ConnectNamedPipe( hpip, &ovi ) )rn rn printf( "client success to connect!\r\n");rn printf( "reading data! \r\n" );rn if( ReadFile( hpip, buff, 200, &readbuf, NULL )) rn rn printf( "success to read data\r\n" );rn printf( "the data read is: %s\r\n", buff );rn rn elsern rn printf( "fail to read data!\r\n" );rn printf( "error message: %ld", GetLastError() );rn rn rn return 0;rnrnrn[/code]rnrn客户端代码:rnrn[code=c]rn#include rn#include rnrnint main()rnrn HANDLE hpip;rn OVERLAPPED ovi = 0;rn char buff[200] = "命名管道测试程序";rn DWORD readbuf;rn printf( "reading named pipe.\r\n" );rn rn if( WaitNamedPipe( TEXT("\\\\.\\pipe\\pipename"), NMPWAIT_WAIT_FOREVER))rn rn hpip = CreateFile( TEXT("\\\\.\\pipe\\pipename"), GENERIC_READ | GENERIC_WRITE , 0, rn NULL, OPEN_EXISTING, 0, NULL );rn if( hpip = INVALID_HANDLE_VALUE )rn rn printf( "fail to open named pipe\r\n" ); rn printf( "error message: %ld", GetLastError() );rn rn elsern rn if( WriteFile( hpip, buff, sizeof( buff ), &readbuf, NULL ) )rn rn printf( "success to write data.\r\n" ); rn rn elsern rn printf( "fail to write data.\r\n" ); rn rn rn rn elsern rn printf( "fail to connect named pipe. \r\n" );rn rn return 0;rnrnrn[/code]rnrn服务器端运行结果:rn-------------------------------------------rnsuccess to create named pipe, waiting for client to connect.rnclient success to connect!rnreading data!rnfail to read data!rnerror message: 109rn------------------------------------------rnrn客户端运行结果:rn----------------------------------------rnreading named pipe.rnfail to open named pipernerror message: 0rn----------------------------------------rnrnrn出错的位置是客户端程序的这一句:rn[code=c]rnrn hpip = CreateFile( TEXT("\\\\.\\pipe\\pipename"), GENERIC_READ | GENERIC_WRITE , 0, rn NULL, OPEN_EXISTING, 0, NULL );rn[/code]rnrn调试了很久也不行,请指教,谢谢。
createfile()创建文件失败的问题
我想以系统时间为名创建文件,下面是我的代码,有个问题一直过不去,运行环境是wince5.0,用VS2005开发;请明白人指教一下:[color=#FF0000]问题见批注[/color]rn 一,类Client中用到的相关代码 rn public:rn int StartSave();rn private:rn static wchar_t save_date[60];rn static int save_callback( void *inst , void* sample);rn 二,StartSave()rn rn ...rn SYSTEMTIME saveNowtime;rn GetLocalTime(&saveNowtime); rn rn swprintf(save_date,(wchar_t*)(_T("\\\\硬盘\\\\%4d-%2d-%2d %2d:%2d:%2d.rec"))rn rn ,saveNowtime.wYear rn rn ,saveNowtime.wMonth rn rn ,saveNowtime.wDay rn rn ,saveNowtime.wHour rn rn ,saveNowtime.wMinute rn rn ,saveNowtime.wSecond); rn .....rnrn这一段的作用是将系统时间转化为一个字符串!rn 我用messagebox打印出save_date的值为\\硬盘\\2003-1-1 12:12:3.recrnrn三,在回调函数中创建文件rnrn hFile=CreateFile(save_date, rn GENERIC_READ|GENERIC_WRITE,rn 0,rn NULL,rn OPEN_ALWAYS,rn FILE_ATTRIBUTE_NORMAL,rn 0);rn if(hFile==INVALID_HANDLE_VALUE)rn rn MessageBox(NULL,_T("文件打开<em>失败</em>"),0,0); rn return 0;rn rnrn 程序编译后无错误,在执行过程中总是打出”文件打开<em>失败</em>“,我查看了错误代码是6号,也就是ERROR_INVALID_HANDLE,这是什么原因导致的啊?rnrn [color=#FF0000]注意:如果我在”hFile=CreateFile(save_date, “ rn 这一行前加wchar_t path[]=_T("\\硬盘\\book.txt");rn 并且把CreateFile的第一个参数换成path,则程序正常运行!所以感觉是save_date出问题了,但是打印出来路径对啊?不知跟宽字符有关吗?save_date和path都是宽字符啊?[/color]
请问createfile打开失败
我的操作如下:rnwchar_t fileName[256] = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789.txt";rnHANDLE hMedia = CreateFile(fileName, GENERIC_READ, rn FILE_SHARE_READ, NULL, OPEN_EXISTING, rn FILE_ATTRIBUTE_NORMAL, NULL);rnrnDWORD error = GetLastError();rnif (INVALID_HANDLE_VALUE == hMedia)rnrn printf("Open media file failed!\n");rnrnrn这样操作,怎么老是<em>失败</em>,请问怎么回事。谢谢。
CreateFile打开USB设备失败
CString uDisk = "\\\\.\\PhysicalDrive";rnCString csNum = "1";//或"2","3",,,,rnHANDLE hDev = CreateFile(uDisk+csNum, GENERIC_WRITE|GENERIC_READ, rn FILE_SHARE_READ|FILE_SHARE_WRITE,rn NULL, OPEN_EXISTING,0,NULL);rnDWORD dwError = GetLastError();rnrn问题是:我在XR系统里以这样的方式打开U盘没有问题,但在Windows7里打开就出错,错误信息是dwError=ERROR_ACCESS_DENIED。我查过,可能是Windows账号权限不够的原因,请问各位大虾,有没有办法可以解决这个问题?谢谢!rnrn补充说明:我这里的U盘是自己做的,因为只有14Kbyte,所以做成FAT12格式的。
CreateFile创建内存映射文件失败
system32\config\system,该文件无法拷贝,无法移动。rn现在我CreateFile文件<em>失败</em>,但我还想把这个文件映射到内存中去,该怎么操作?rn
CreateFile返回创建文件失败
m_hFile = ::CreateFile((LPCTSTR)m_strFilePath, GENERIC_READ | GENERIC_WRITE ,rn FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);rn if(m_hFile == INVALID_HANDLE_VALUE)rn rn AfxMessageBox("创建文件<em>失败</em>");rn return -1;rn rn我单步走到这里的时候,老是近入if语句,不知道是怎么回事?rn我在m_strFilePath值为c:\\csl.txt,如果我把m_strFilePath值改为d:\\csl.txtrn单步调试就能够顺利跳过去,但是我在CreateFile设置了CREATE_ALWAYS,不管他存在不存在我都创建,怎么会返回INVALID_HANDLE_VALUE.~我想把已经存在c:\csl.txt覆盖一次<em>为什么</em>不行啊!~有什么办法吗>
hVXD=CreateFile失败
hVXD=CreateFile("\\\\.\\Inte.vxd",0,0,0,OPEN_EXISTING,FILE_FLAG_DELETE_ON_CLOSE,0);rn老是出现下面情况rnhVXD==INVALID_HANDLE_VALUErn前提有把Inte.vxd和Inte.inf拷贝到system32里面。rn请指教!rn
CreateFile 为什么
FILE *hFile;rn下面这个代码编译通不过去,<em>为什么</em>rnrnhFile =CreateFile(lpReq->szFileName, rn GENERIC_READ,rn FILE_SHARE_READ,rn (LPSECURITY_ATTRIBUTES )0,rn (DWORD ) OPEN_EXISTING,rn (DWORD ) FILE_ATTRIBUTE_NORMAL,rn (HANDLE)NULL);rnrnrnrn下面这个代码编译通过去了,<em>为什么</em>rnhFile =(FILE*) CreateFile(lpReq->szFileName, rn GENERIC_READ,rn FILE_SHARE_READ,rn (LPSECURITY_ATTRIBUTES )0,rn (DWORD ) OPEN_EXISTING,rn (DWORD ) FILE_ATTRIBUTE_NORMAL,rn (HANDLE)NULL);
CreateFile打开物理磁盘失败,失败返回代码87,为什么呢?
[code=C/C++]rn#include "stdafx.h"rn#include rn#include rnint main() rn HANDLE hFile=CreateFile("\\\\.\\PhysicalDrive0",GENERIC_READ,rn FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);rn if(INVALID_HANDLE_VALUE==hFile)rn printf("open error %d\n",GetLastError());rn rn return 0;rnrnrn[/code]rn运行输出:rnopen error 87rnPress any key to continue
为什么SetWallpaper调用失败
void SetDesktopWallpaper()rnrn HRESULT hr;rn IActiveDesktop *pActiveDesktop;rn CoInitialize(NULL); rn hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,IID_IActiveDesktop, (void**)&pActiveDesktop);rn if (hr!=S_OK)rn return;rn WALLPAPEROPT wpOptions;rn wpOptions.dwSize = sizeof(WALLPAPEROPT);rn wpOptions.dwStyle = WPSTYLE_STRETCH;rn hr=pActiveDesktop->SetWallpaperOptions(&wpOptions,0); rnrn COMPONENTSOPT comps;rn comps.dwSize = sizeof comps;rn comps.fEnableComponents = TRUE;rn comps.fActiveDesktop = TRUE;rn rn hr=pActiveDesktop-> SetDesktopItemOptions(&comps,0); rn //Insert code to call the IActiveDesktop methodsrn rnrn if(FAILED(pActiveDesktop->SetWallpaper(L"D;\\1.jpg",0)))rn return; rn hr=pActiveDesktop->ApplyChanges(AD_APPLY_ALL); rn rn pActiveDesktop->Release();rn CoUninitialize();rnrnrnrnhr 返回一直是S_OKrn执行完成后,桌面显示蓝色背景,且右键桌面属性->桌面图片就是设置的图片名 rn<em>为什么</em>就是不显示? 哪位高手解答一下,谢谢
调用SetWindowLong为什么失败
我想在创建的窗口上附加一个类的指针,用如下代码:rnrnWNDCLASS wndclass;rnconst char *ProviderClass = "TestWindow";rnHWND Window;rn rnwndclass.style = CS_HREDRAW | CS_VREDRAW;rnwndclass.lpfnWndProc = (WNDPROC)WindowProc;rnwndclass.cbClsExtra = 0;rnwndclass.cbWndExtra = 4;rnwndclass.hInstance = NULL;rnwndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);rnwndclass.hCursor = LoadCursor(NULL, IDC_ARROW);rnwndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);rnwndclass.lpszMenuName = NULL;rnwndclass.lpszClassName = ProviderClass;rn rnif (RegisterClass(&wndclass) == 0) return NULL;rn rn// Create a window.rnif ((Window = CreateWindow(rn ProviderClass,rn "",rn WS_OVERLAPPEDWINDOW,rn CW_USEDEFAULT,rn CW_USEDEFAULT,rn CW_USEDEFAULT,rn CW_USEDEFAULT,rn NULL,rn NULL,rn NULL,rn NULL)) != NULL)rnrn Wnd *w = new Wnd;rn if ( long s = SetWindowLong(Window, 0, (long)w ) )rn return Window;rnrn long code = GetLastError();rn rn DestroyWindow(Window);rn Window = 0;rn rn return NULL;rnrnrn但是SetWindowLong执行错误,错误码是42(66"网络资源类型错误。")。不知道<em>为什么</em>?rn
为什么调用失败呢?
前台:rn $.ajax(rn type: "POST",rn contentType: "application/json; charset=utf-8",rn url: "Default.aspx/PrintLabel",rn data: "'LOT':'123456789'", rn success: function (result) rn alert("o000");rn alert(result.d);rn ,rn error: function (a) alert("error") rn );rnrn后台:rn [WebMethod]rn public static string PrintLabel(string LOT)rn rn return LOT; rn rnrn结果第一个弹出框是对的,第二个一致是0,即使我后台写 return “aaaa”; 还是弹出0
为什么调用对话框失败?
我<em>调用</em>对话框的部分程序如下:rn#include "stdafx.h"rn#include "nana.h"rn#include "nanaDlg.h"rn#include "Search.h"rn#include "onnect.h"rn#include "circle.h"rn.....................................rn......................................rnvoid CNanaDlg::OnOK() rnrn // TODO: Add extra validation herern rn CDialog::OnOK();rn UpdateData(true);rn if(m_choice=="1. 顶点查找和图的遍历")rn Search a;rn a.DoModal();rn rn else if(m_choice=="8. 求有向图中的强连通分量")rn Connect b;rn b.DoModal();rn rn else if(m_choice=="6. Euler回路和Hamilton回路")rn circle c;rn c.DoModal();rn rnrn<em>调用</em>Connect这个对话框成功,却<em>调用</em>circle这个对话框<em>失败</em>,好奇怪rn而且我在circle.cpp中已经加入了rn#include "nana.h"rn#include "nanaDlg.h"rn#include "circle.h"rn这些头文件rn其中nana 是主对话框rn
为什么调用_syscall1失败
最近在做哈工大的操作系统实验,做到第二个的时候出现了一些问题,怎么也解决不了。就是<em>调用</em>_syscall1或者_syscall2的时候,GCC老是报错说里面的参数是未知类型,,我看有的人加 分号 ; 有的人不加,我两个都试了 都不能编译成功rn[img=https://img-bbs.csdn.net/upload/201810/03/1538565273_545100.png][/img]rn[img=https://img-bbs.csdn.net/upload/201810/03/1538565355_1454.png][/img][img=https://img-bbs.csdn.net/upload/201810/03/1538565361_932983.png][/img]rnrn
wsasocket 为什么调用失败
请教一下,<em>为什么</em> 这个<em>调用</em><em>失败</em>rn m_hListenSocket = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, NULL, WSA_FLAG_OVERLAPPED);rnwsagetlasterror 返回错误6,句柄无效rnrn已经包含rn#pragma comment(lib,"ws2_32")rn#include rnrn执行wsasocket前<em>调用</em>rn WORD wVersionRequested;rn WSADATA wsaData;rn int err;rn rn wVersionRequested = MAKEWORD( 2, 2 );rn rn err = WSAStartup( wVersionRequested, &wsaData );rn if ( err != 0 ) rn return FALSE;rn rnrn rn if ( LOBYTE( wsaData.wVersion ) != 2 ||rn HIBYTE( wsaData.wVersion ) != 2 ) rn WSACleanup( );rn return FALSE; rn rnrnrn
为什么调用SetWindowHookEx失败
我的代码如下:rnhThread = CreatThread(NULL, 0, ThreadProc, NULL, 0, &dwThreadID);rnif(hThread != NULL)rnrn //下面这个语句<em>调用</em><em>失败</em>.rn hHook = SetWindowHookEx(WH_CBT, HookProc, NULL, dwThreadID);rnrn //下面这个语句执行成功.rn hHook = SetWindowHookEx(WH_CBT, HookProc, NULL, GetCurrentThreadID());rnrnrn请问各位大虾,<em>为什么</em>第一个语句<em>失败</em>?
为什么RegQueryValue调用失败
rnBOOL COption::Register()rnrn CString str;rn HKEY hRegKey;rn BOOL bResult;rn str = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");rn if(::RegOpenKey(HKEY_LOCAL_MACHINE, str, &hRegKey) != ERROR_SUCCESS) rn rn bResult = FALSE;rn rn elsern rn char Transfer_Get[100];rn long Len = 100;rn if (::RegQueryValue(hRegKey,"Transfer",Transfer_Get,&Len) != ERROR_SUCCESS)//查询键值 rn rn bResult = FALSE;rn rn elsern rn bResult = TRUE;rn rn rnrn RegCloseKey(hRegKey);rn return bResult;rnrnrn我的应用程序名为Transfer,注册了开机自动运行,但是<em>为什么</em>我用上面的查询函数时RegQueryValue总是<em>调用</em><em>失败</em>?
USB CreateFile 失败 GetLastError() = 2
for循环到第4次时CreateFile就<em>失败</em>了,GetLastError值为2,这是什么原因啊,怎么解决。rnrnBOOL HY_Get_USBDevice(void)rnrn CHAR HCName[32];rn int HCNum;rn HANDLE hHCDev;rnrn for (HCNum = 0; HCNum < 10; HCNum++)rn rn sprintf(HCName, "\\\\.\\HCD%d", HCNum);rn hHCDev = CreateFile(HCName,rn GENERIC_WRITE,rn FILE_SHARE_WRITE,rn NULL,rn OPEN_EXISTING,rn 0,rn NULL);rn if (hHCDev == INVALID_HANDLE_VALUE)rn {rn int rst = GetLastError();rn break;rn }rn rn ......rn
使用createfile总是失败,请教
使用CreateFil("C:\tt.txt",GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);总是<em>失败</em>,向各位请教
CreateFile失败的问题。请帮忙。
serverHandle = CreateFile( pipeName, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | E_FLAG_WRITE_THROUGH, NULL);rnrnif(serverHandle != INVALID_HANDLE_VALUE)rn break;rnrn程序有时正常运行。但是,又是在if语句之前就出错了。不知道是何原因。
CreateFile打开USB端口失败
CreateFile函数打开USB端口<em>失败</em>,GetLastError 返回错误为 32,表示端口被其它进程打开,但任务管理器没发现多余的软件rn同个软件在其它几台电脑上用是没问题的,CreateFile都是可以打开端口并收发数据,但有一台手提电脑上切总提示以上错误rn如果把CreateFile改为共享的方式打开端口是可以的,但是读写数据是不行的,rn请问这是什么原因呢,是系统的什么设置吗?rn谢谢
win32串口编程中CreateFile失败
我想在win32下实现串口编程,下了一个例子照着打进去后怎么都创建<em>失败</em>。。。。各位兄弟姐妹们帮帮忙吧,谢谢各位了先rnHANDLE hCom=CreateFile((LPWSTR)("COM1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,rnFILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL);rnif(hCom==(HANDLE)-1)rnrnreturn false;rnrn怎么每次都<em>失败</em>呢。。。。我就纳了个闷了。。。rn我已经用虚拟串口工具虚拟了COM1和COM2端口的连接rn也用串口调试工具测试了下,显示这两个端口都空闲,可就是连不上啊。。。。rn[img=http://hi.csdn.net/space-3555420-do-album-picid-653506.html][/img]rn[img=http://hi.csdn.net/space-3555420-do-album-picid-653505.html][/img]
createfile()的调用问题
请问打开notepad是<em>调用</em>那一个函数,<em>createfile</em>()??,但我拦截住了<em>createfile</em>(),word和excel不能打开,但notepad还是能打开的,难道word跟notepad打开方式不一样?rnrn还有一个问题,我昨天发了一个贴,rnhttp://topic.csdn.net/u/20080529/10/32a5f749-fef4-414f-9992-fc1e43ee12a2.htmlrnrn既然我拦截了<em>createfile</em>(),比如是D盘的<em>createfile</em>();D盘里的一切都不能复制到别的盘,里面的大哥是这样解释的,因为复制文件的操作,先打开文件CreateFile ,读文件ReadFile ,打开另外一个文件CreateFile 再写文件WriteFile ,word跟excel因为不能<em>调用</em><em>createfile</em>(),所以word跟excel不能打开,但我rn不明白既然notepad不<em>调用</em><em>createfile</em>(),<em>为什么</em>notepad还是不可以复制去别的盘?rnrn这个问题都困扰了我好几个星期了,请大侠们帮帮,本贴可以加到100分rnrn
createfile 调用参数问题
<em>createfile</em>第二个参数可以设置为这两个值GENERIC_READ,GENERIC_WRITE的组合,那么<em>调用</em>的时候应该怎么写啊?rnC里好像可以这样写,可是pb里应该怎么写呢?
createfile如何调用driver?
就是返回一个driver的handle,请指教
连续两次调用CreateFile打开USB设备,第二次失败
连续两次用CreateFile打开USB设备,第一次以读的方式,第二次以写的方式。读方式打开成功,写方式打开<em>失败</em>,<em>调用</em>GetLastError返回拒绝访问,但是我直接以写的方式打开,是成功的,这是<em>为什么</em>呢?
为什么isleadbyte调用失败
就是想试验一下isleadbyte的有效性,使用如下代码: rn rn const char str[] = "字母a是一个字节的"; rn rn int nLen = strlen(str); rn int nLead = 0; rn rn for (int i = 0; i , nLen, nLead); rn rn 结果输出: nLen: 17 rn nLead: 0 rn rn 就是一个前导字符都没找到啊,为深么啊? rn 这个函数使用有问题?
两次调用++,编译失败,为什么?
[code=C/C++]rnint main(void)rn int i=0;rn int j=++i++;rn return 0;rn[/code]rnrn我的用意是: i加1,赋值给j,然后i自己再加1。结果是i=2,j=1。rn可是就是这3行代码,在VC10下面编译,竟然有错:rnrnerror C2105: '++' needs l-valuernrn错在哪里呢?
SetFocus函数为什么调用失败
我看了MSDN中的描述:If the function succeeds, the return value is the handle to the window that previously had the keyboard focus. If the hWnd parameter is invalid or the window is not attached to the calling thread's message queue, the return value is NULL. To get extended error information, call GetLastError.rnrn说有两种情况会<em>失败</em>:rn1 hWnd parameter is invalid rn2 the window is not attached to the calling thread's message queuernrn我看了,不是第二种情况。rn我想知道,什么叫“hWnd parameter is invalid ”,而且我<em>调用</em>GetLastError返回0.rnrnrnrn
为什么调用 DialogBox 会失败
#include "stdafx.h"rn#include "resource.h"rnBOOL CALLBACK DialogProc(rn HWND hwndDlg, // handle to dialog boxrn UINT uMsg, // messagern WPARAM wParam, // first message parameterrn LPARAM lParam // second message parameterrn)rnrnswitch(uMsg)rnrncase WM_INITDIALOG:rnreturn TRUE;rncase WM_COMMAND:rnif(LOWORD(wParam)==IDOK||LOWORD(wParam)==IDCANCEL)rnEndDialog(hwndDlg,LOWORD(wParam));rnreturn TRUE;rnrnrnreturn false;rnrnint APIENTRY WinMain(HINSTANCE hInstance,rn HINSTANCE hPrevInstance,rn LPSTR lpCmdLine,rn int nCmdShow)rnrnif(DialogBox(hInstance,MAKEINTRESOURCE(IDD_CHAT_DIALOG),NULL,(DLGPROC)DialogProc)==-1)rn rnMessageBox(NULL,"Call DialogBox failed.","Error",MB_ICONEXCLAMATION);rnreturn -1;rn rnreturn 0;rnrnrnrnNew->Win32 Application->A simple Win32 application->finishrnrn然后 Insert->Recource 插入对话框,编译没有错误,可对话框就是不显示,请问这是<em>为什么</em>呢?但我改成 New->Win32 Application->A typicl "hello World" application->finish 就可以显示对话框,这是<em>为什么</em>呢?rnrn
为什么调用StgCreateDocfile会失败
IStorage *pStg=NULL;rnHRESULT hr=::StgCreateDocfile(L"D:\\MyStorageFile",rn STGM_READWRITE,rn 0,&pStg);rnif(FAILED(hr))rnrn cout<;rn exit(0);rnrn谢谢
为什么调用InterruptInitialize总是失败
我现在做can总线的驱动,在中断部分<em>调用</em>InterruptInitialize总是<em>失败</em>,下面是我的代码rnhEvent=CreateEvent(0,FALSE,FALSE,NULL);rn if(hEvent)rn rn RETAILMSG(1,(TEXT("CAN:CreateEvent_okaaaaaaaaaaaaaaaaaaaa"))); rn rn rn hCanThread=CreateThread(NULL,rn 0,rn CanIST,rn NULL,rn CREATE_SUSPENDED,rn &dwThreadID);rn if(hCanThread)rn rn RETAILMSG(1,(TEXT("CANTHREAT:CREATETHREAD_OKhhhhhhhhhhhhhhhhhhhhhhhhhh\n")));rn rn elsern rn RETAILMSG(1,(TEXT("CANTHREAT:CREATETHREAD_FALSEhhhhhhhhhhhhhhhhhhhhhhhhhh\n")));rn return 0;rn rnrn dwISTPriority=253;rnrn if(!CeSetThreadPriority(hCanThread,dwISTPriority))rn rn RETAILMSG(1,(TEXT("CeSetThreadPriority Failed!!hhhhhhhhhhhhhhhhhhhhhhhhhh\n")));rn rn if(!InterruptInitialize(SYSINTR_CAN,hEvent,NULL,0))rn rn RETAILMSG(1,(TEXT("InterruptInitialize Failed!!hhhhhhhhhhhhhhhhhhhhhhhhhh\n")));rn rn ResumeThread(hCanThread);rn前面的几步都没有问题,就是在连接系统中断号和事件的时候<em>失败</em>?rn我的其他中断的设置都做了,驱动编译没有问题rn请大家帮忙rn
为什么调用Shell_NotifyIcon函数失败
<em>调用</em>rnPublic Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias " Shell_NotifyIconA" ( _rn ByVal dwMessage As Long, _rn lpData As NOTIFYICONDATA _rn) As Longrn函数时,系统提示Can't find DLLentry point Shell_NotifyIconA in shell32.dll这样的错误。我该怎样<em>调用</em>它才能避免发生上面的错误了?rn
调用很简单的存储过程,失败为什么
存储过程:rnCREATE PROCEDURE pro_system rn@newsystemid varchar(30), rn@systemname varchar(60),rn@systemmanid varchar(200),rn@systemman varchar(200)rnASrn insert into Tsystem(systemid,systemname,systemmanid,systemman) values (@newsystemid,@systemname,@systemmanid,@systemman)rnGOrn---------------------------------------------------------------------------------------rnBeanFunction:rnrnpackage test2;rnimport java.sql.*;rnimport java.util.List;rnrnpublic class BeanFunction rnrn public Connection Pcon;rn public Statement Pstatement;rnrn //连接rn public Statement con_statement()throws Exceptionrn rn tryrn rn Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();rn Pcon = java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://wjh:1433;DatabaseName=wjh", "sa", "");rn Pstatement = Pcon.createStatement();rn return Pstatement;rn rn catch(Exception e)rn rn e.printStackTrace();rn return null;rn rn rn rn //新增rn public void insert()throws Exceptionrn rn tryrn rn con_statement().execute("insert Tsystem (systemid,systemname,systemmanid,systemman,popedom) values('11','22','33','44','55')");rn Pstatement.close();rn Pcon.close();rn rn catch(Exception e)rn rn e.printStackTrace();rn rn rnrn //存储过程rn public void doStore()throws Exceptionrn rn String strSQL = "call pro_system";rn java.sql.CallableStatement sqlStmt = Pcon.prepareCall(strSQL);rn rn sqlStmt.setString(1,"11");rn sqlStmt.setString(2,"22");rn sqlStmt.setString(3,"33");rn sqlStmt.setString(4,"44");rnrn sqlStmt.executeUpdate();rn sqlStmt.close();rn Pcon.close();rn rnrn---------------------------------------------------------------------------------------rnjsp:rn...rnrnrnrn...rn-------------------------------------------------------------------------------------rn运行:rn其中A是正确的。rn而B出错,错误信息为:rnjava.lang.NullPointerExceptionrn at test2.BeanFunction.doStore(BeanFunction.java:114)rn at org.apache.jsp.open_0005fjsp$jsp._jspService(open_0005fjsp$jsp.java:101)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)rn ...rn请问<em>为什么</em>呀?
为什么调用API失败呢?
我的系统是WIN XP,程序中用了下面的API,然后程序运行时报错:说找不到RegisterServiceProcess函数的入口。rnrn请问,该怎样解决?rnrnrnrnrnrnrnrnrnPrivate Declare Function GetCurrentProcessId Lib "kernel32" () As LongrnrnPrivate Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As LongrnrnPrivate Const RSP_SIMPLE_SERVICE = 1rnPrivate Const RSP_UNREGISTER_SERVICE = 0rnrnPrivate Sub Form_Load()rnrn Call RegisterServiceProcess(GetCurrentProcessId, 1)rnrnEnd Subrn
vs2008中用QT调用createfile打开分区失败的原因
vs2008中用QT<em>调用</em><em>createfile</em>打开分区<em>失败</em>的原因rn我在vs2008中编译一个测试代码,打开一个分区,没有问题!rnrn测试通过后,我在vs2008里建立了一个QT工程,然后把测试代码嵌入里面,希望可以在图形界面中选择需要打开的分区,编译通过,但死活都是打开分区<em>失败</em>!rnrn打开分区的代码如下:rn_TCHAR volumePath[7];rn_sntprintf(volumePath, 6, _T("\\\\.\\%c:"), volume);rnvolumePath[6] = _T('\0');rnhVolume = CreateFile((LPCTSTR )volumePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,rnNULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);rnrnrn查找返回的错误代码显示的错误是:rn刚开始的错误码是2:意思是找不到打开的文件rn换了好几个分区来打开时变成了这个错误:@err,hr 0x0000007b 文件名、目录名或卷标语法不正确。 unsigned longrnvolumePath的值显示是:\\.\\C:rn_TCHAR的大小是1rn不知道qt对这种反斜杠的文件名:\\.\\C: 有没有敏感,以致打不开分区。rnrn望知道错误的大侠指点rnrnqt4.6.2 vs2008版
为什么我用_mkdir和CreateFile时总是失败
_mkdirrnCreateFilern哎,我从来没有创建成功过,<em>为什么</em>呢?rnrn
为什么我在应用命名管道的时候会CreateFile会失败?
hh:=CreateFile(pchar(pipename),GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE,NiL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE or FILE_FLAG_WRITE_THROUGH,0);rnrnhh:=CreateFile(pchar(pipename),GENERIC_READ or GENERIC_WRITE, 0,null,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,null);rnrnhh:=CreateFile(Pchar(pipename),GENERIC_WRITE or GENERIC_READ,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);rnrnhh:= CreateFile(Pchar('\\.\pipe\Server'),GENERIC_WRITE or GENERIC_READ,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);rnrn哪个都不行`而且我单独测试也不行(直接用buttonClick事件执行也不行),直接hh=INVALID_HANDLE_VALUE 啥原因呢`rn
CoCreateInstance 调用成功, CoGetClassObject 调用失败,为什么?
同题,rn我只是用ATL 的向导程序,建立EXE(进程外) 工程, 并且添加一个普通ATL COM 对象,rnrn<em>为什么</em>在客户程序中<em>调用</em>CoCreateInstance成功,但<em>调用</em>CoGetClassObject 却<em>失败</em>.rnrn在<em>调用</em>CoGetClassObject 我检查到Server EXE 曾经载入过内存,但CoGetClassObject <em>失败</em>后,就从内存中卸了.rnrn<em>为什么</em>会这样呢??rnrn(我是想实现单例,类工厂同时实现了客户要求的功能,所有客户都使用同一个工厂对象实例)
为什么CreateFile打开驱动第一次成功第二次失败
在ring3,利用CreateFile打开驱动rnm_hDevice = CreateFile (_T("\\\\.\\UHFControl"), 0, 0, NULL, OPEN_ALWAYS, FILE_FLAG_OVERLAPPED, NULL);rn在ring0,创建设备rnrn status = IoCreateDevice (DriverObject,rn sizeof (CControlDeviceExtension*),rn &m_NameString, // No Namern m_DriverType,rn FILE_DEVICE_SECURE_OPEN,rn FALSE,rn &m_Self);rn这是一个usb hub过滤驱动,进行USB设备的重定向,结果对第一个设备进行重定向可以成功,第二个就偶尔会<em>失败</em>。通过getlasterror获得的错误代码是2,系统找不到指定的文件rn求指点,<em>为什么</em>啊?
为什么我用CreateFile打开串口失败呢?
<em>为什么</em>用CreateFile打开<em>失败</em>,返回值是~0rnCreateFile("com2", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL, NULL);rn串口时虚拟的串口,rn但是open能打开也能传输数据rnopen("com2",O_RDWR)rn
【求助】为什么我用CreateFile打开串口总是失败
在 WIN2K + VB6 下用 CreateFile 打开串口总是, 总是返回 -1rnrn Dim lret As Longrn lret = CreateFile("COM3", GENERIC_READ Or GENERIC_WRITE, _rn 0&, 0&, OPEN_EXISTING, 0&, 0&)rnrnrn If lr = INVALID_HANDLE_VALUE Thenrn MsgBox GetAPIError, vbExclamation, "打开串口出现错误:"rn Init_COMM = 0rn Exit Functionrn End Ifrnrn然后 用 FormatMessage 返回 错误描述是: 操作已完成 ,可是返回的 lret = -1 啊, 同时在 超级终端上读取打开,关闭,通讯一切正常。rnrnCOM3 是我用 USB 虚拟出的串口设备。
c# 中调用CreateFile的问题
<em>为什么</em>我这样声名 总是提示int(应输入class、delegate、enmu、interface或struct)rnusing System.Runtime.InteropServices;rnrn[StructLayout(LayoutKind.Sequential)]rnpublic struct SECURITY_ATTRIBUTES rnrn public int nLength;rn public int lpSecurityDescriptor;rn public int bInheritHandle;rnrn[DllImport("kernel32.dll", EntryPoint="CreateFile")]rnpublic static extern int CreateFile (rn ^^^^^^(应输入class、delegate、enmu、interface或struct)rnstring lpFileName,rnint dwDesiredAccess,rnint dwShareMode,rnref SECURITY_ATTRIBUTES lpSecurityAttributes,rnint dwCreationDisposition,rnint dwFlagsAndAttributes,rnint hTemplateFilern);
InstallShield 怎样调用API CreateFile ?
InstallShield 有个内部函数CreateFile, 但我要<em>调用</em>的是API函数, 编译提示定义已经存在.rn
怎么调用CreateFile对于minidriver
我看testcap里的minidiver里没有设备名和符号名,那应用程序怎么和这个驱动交互啊,谢谢!
EVC4.0下怎样调用控制台?CreateFile(...)?
模拟器下是没有控制台输出的,想<em>调用</em>控制台。MSDN上说是可以<em>调用</em>CreateFile,且第一个参数是CONn:(n = 0 - 9),但没有成功。哪位大虾知道,请指教,非常感谢。
CreateFile调用 IIC驱动问题
再EVC下用CreateFile()打开IIC设备成功返回句柄,用返回的句柄<em>调用</em>WriteFile(),WriteFile的返回值wRetSize为0;GetLastError返回的也为0rn代码如下:rnhT2C = CreateFile(TEXT("I2C1:"),rn GENERIC_READ|GENERIC_WRITE,rn 0, NULL, OPEN_EXISTING,rn FILE_ATTRIBUTE_NORMAL, NULL);rnif (hT2C == INVALID_HANDLE_VALUE)rnrnrn if (GetLastError() == ERROR_DEV_NOT_EXIST)rn rn // register I2C device driverrn hDriver = RegisterDevice(TEXT("I2C"), 1, TEXT("I2C.DLL"), 0);rn if (!hDriver)rn rn RETAILMSG(1, (TEXT("Failed to register I2C device driver.\r\n")));rn rn hT2C = CreateFile(TEXT("I2C1:"),rn GENERIC_READ|GENERIC_WRITE,rn 0, NULL, OPEN_EXISTING,rn FILE_ATTRIBUTE_NORMAL, NULL);rn rn rn if (hT2C == INVALID_HANDLE_VALUE)rn rn dwErrorCode = GetLastError();rn return dwErrorCode ;rn rnrnrnrnWriteFile ( hT2C, BUFFER, writesize, &wRetSize, NULL);rnrn//判断存储是否成功rnif (!wRetSize)rnrn dwErrorCode = GetLastError();rn CloseHandle( hT2C );rn return 1; rn
CreateFile
HANDLE hFile; rn rn hFile = CreateFile(filename, // open MYFILE.TXT rn GENERIC_READ, // open for reading rn FILE_SHARE_READ, // share for reading rn NULL, // no security rn OPEN_EXISTING, // existing file only rn FILE_ATTRIBUTE_NORMAL, // normal file rn NULL); rn rn 这是msdn上的例子,先用着好好的,创建文件也成功了,后来突然一直编译错误:rn error C2660: 'CreateFileA' : function does not take 7 parametersrn 但在MSDN里就是7个参数,请问有知道什么原因的么。
createfile()打开串口失败,求解答
hCom = CreateFile("COM1", //打开串口1rn GENERIC_READ | GENERIC_WRITE, //允许读和写操作rn 0, //独占方式rn NULL,rn OPEN_EXISTING, //打开一个存在的串口rn FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, //异步方式打开rn NULLrn );rnCreateFile()的返回值为INVALID_HANDLE_VALUE。rn用GetLastError()得到返回值为2,系统找不到指定路径。rnrn这个,要怎么改?rn谢谢大家。
为什么样下面总是CreateFile失败
HANDLE hCom; //global handlern hCom=CreateFile("COM2",GENERIC_READ && GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);rn这样总是打不开,请问这是<em>为什么</em>?
在COM 中使用createfile 失败的原因?
我在COM中<em>调用</em> CREATEFILE 结果返回 INVALID_HANDLE_VALUE,从而无法进行下一步的操作。rnrn是什么原因???rnrnm_hFile = CreateFile(pszFilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);rn结果 (m_hFile == INVALID_HANDLE_VALUE)
新手求教CreateFile()打开失败,返回5
以前没有接触过windows的API,因为程序有用到,所以从网上复制了一个函数rnrn系统是win7,用工具激活为正版,VS2013社区版,程序启动方式为“右键-》已管理员身份运行”rnrn函数功能是判断某个盘符是否为U盘还是移动硬盘(需要把这两个和本地硬盘区别),其中有段代码用到了CreateFile(),问题也是出现在这里,出错,返回5rnrn[code=c]rn WCHAR newDrive[256]; //改函数传递进来的参数是CHAR* drive,这里转换为WCHARrn memset(newDrive, 0, sizeof(newDrive));rn MultiByteToWideChar(CP_ACP, 0, drive, strlen(drive)+1, newDrive, sizeof(newDrive)/sizeof(newDrive[0]));rn _wsetlocale(LC_ALL, newDrive);rn wprintf(L"%s", newDrive); //测试下转换是否正确,这里控制台显示结果"C:"而不是"C:/"rn //----rn hDevice = CreateFile(rn newDrive, // drive to openrn GENERIC_READ | GENERIC_WRITE, // access to the drivern FILE_SHARE_READ | FILE_SHARE_WRITE, //share modern NULL, // default security attributesrn OPEN_EXISTING, // dispositionrn 0, // file attributesrn NULL // do not copy file attributern );rn if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drivern rn fprintf(stderr, "CreateFile() Error: %ld\n", GetLastError()); //显示无法打开,错误5rn return DWORD(-1);rn [/code]rnrn我想问下<em>为什么</em>不能打开本地的C盘或者D盘或者E盘?
CreateFile ReadFile 读取图片文件失败
通过CreateFile、ReadFile 读取图片文件,用于模拟网页POST上传至网上空间。但是通过ReadFile函数获得字符数组时只有一个符号‘?’,说明读取错误。但是用同样的方法,[b]读取test.txt文本文件是正确的。[/b]rn [color=#0000FF]请问不能通过CreateFile、ReadFile 获得图片文件数据吗?我的最终目的将图片数据先读到内存中,然后再模拟网页POST将图片上传至网上空间。[/color]rnrn以下为读取jpg图片文件代码:rnrn HANDLE hFile; rn int dwFileSize;rn hFile=CreateFile("F:\\1.jpg",GENERIC_READ,0, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); rn dwFileSize=GetFileSize(hFile,NULL); rn if (hFile == INVALID_HANDLE_VALUE) rn rn AfxMessageBox("文件打开错误");rn return ;rn rn char *ansiPtr;rn ansiPtr=new char[dwFileSize + 1];rn ZeroMemory(ansiPtr,dwFileSize + 1);rnrn if (ReadFile(hFile, ansiPtr, dwFileSize, &dwBytesRead, NULL)) rn rn ansiPtr[dwFileSize]='\0';rn rnrn
Win7下CreateFile创建文件失败错误代码5
在系统目录下:如C:\Program Files\ 目录,创建文件<em>失败</em>, 错误代码是5,表示拒绝访问。 rn知道是应该权限问题,但我就想用普通用户运行,并使它能创建文件。是怎么做。有没有好办法!!
CreateFile为什么返回参数错误?
[code=C/C++]rnCString strLastError;rn CString strFilePath = _T("\\windows\\wz.txt");rn HANDLE hIDFile = CreateFile(strFilePath,GENERIC_READ,FILE_SHARE_READ,NULL,rn OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);rn if (INVALID_HANDLE_VALUE == hIDFile)rn rn strLastError.Format(_T("%s打开<em>失败</em>,错误信息:%d"),strFilePath,GetLastError());rn AfxMessageBox(strLastError);rn return ;rn rn[/code]rn读取已经存在的文件wz.txt,<em>为什么</em>CreateFile返回了参数错误?
DeviceIoControl的时候createfile失败GetLastError=5
我想在win32下检测PC上的可移动磁盘,参照http://www.freeors.com/bbs/viewthread.php?tid=506做了一下rn可是实现的时候有问题,就是<em>createfile</em><em>失败</em>GetLastError=5(拒绝访问,我手动建立文件是没有问题的),谁给分析下是什么原因造成的?rn参见下面代码rn[code=C/C++] rnLPCTSTR sDrivePath = s;rnUINT DiskType =GetDriveType(sDrivePath); rnswitch(DiskType) rn rn case DRIVE_NO_ROOT_DIR: rn return; rn case DRIVE_REMOVABLE:rn rn strSDDirver = sDrivePath;rn sprintf(chDeviceName, "\\\\.\\%c:", 'G');//SD卡所在盘符rn hDevice = CreateFilern (chDeviceName, rn GENERIC_READ | GENERIC_WRITE,rn FILE_SHARE_READ | FILE_SHARE_WRITE,rn NULL, rn OPEN_EXISTING,rn NULL,rn NULL); rn int i = GetLastError();//[b]错误码 5[/b]rnrnrnif (hDevice != INVALID_HANDLE_VALUE) rn rn if (DeviceIoControl( rn hDevice, rn IOCTL_STORAGE_CHECK_VERIFY, rn NULL, rn 0, rn NULL, rn 0, rn &cbBytesAct, rn NULL))rn rn....rnrn...rnrn[/code]
wince usb 数据采集程序 CreateFile 失败
开发一个 wince usb 数据采集程序,使用<em>createfile</em>打开usb设备<em>失败</em>。rnrn此设备使用标准的USB设备提供了温度采集功能,在XP系统上一切正常。使用了CreateFile 、ReadFile进行数据读取。移植到WinCe系统,始终无法打开USB设备。有做过的吗 帮忙解释下。rnrn代码如下:rnHANDLE hDriver = CreateFile (rn _T("HID1:"),//USBSERIAL_NAMErn GENERIC_READ | GENERIC_WRITE,rn 0,rn NULL, rn OPEN_EXISTING, 0, rn NULL);rn if (hDriver == INVALID_HANDLE_VALUE)rn rn rn return 0;rn
CreateFile这个函数为什么在非管理员User下调用失败,有解决办法吗?
CreateFile这个函数<em>为什么</em>在非管理员User下<em>调用</em><em>失败</em>,GetLastError=5(拒绝访问)rn有办法解决这个问题吗?请达人指点一下。
CreateFile打开串口失败(com10以上)
// get a handle to the port m_hComm = CreateFile(_T(&amp;quot;\\.\COM11&amp;quot;), // communication port string (COMX) GENERIC_READ | GENERIC_WRITE, // read/write types 0, // comm devices must be opened wit...
CreateFile 访问磁盘失败,错误代码5,拒绝访问
CreateFile(rn L"d:", rn GENERIC_READ, rn FILE_SHARE_READ, rn NULL, rn OPEN_EXISTING, rn FILE_FLAG_NO_BUFFERING, rn NULL);rnrn关了UAC,并且使用管理员权限也没用rn这个是什么原因,真的一点机会都不给?
【急】vs2005 串口 createFile 函数创建失败???
hCom=CreateFile(_T("COM1"),rn GENERIC_READ|GENERIC_WRITE,rn 0,rn NULL,rn OPEN_EXISTING,rn FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,rn NULL);rnrnrn怎么改???rn用的是UNICODE
WINCE6,串口打开失败,CreateFile()返回-1
环境 VS2008,WINCE6,WINCE系统里有“COM1”,我用串口调试终端能打开”COM1“并且能发送与接收数据rn为了怕搞错串口名称,我干脆打开COM1-COM5,并且跟踪 m_hComm的值,发现返回的全部是 -1(0xffffffff), 这是我建的一个WINCE测试工程,就在下面这个函数里添加了如下代码,不知为何CreateFile()会返回 -1,请高手指定一二,谢谢rnrnBOOL CWinceUartTestDlg::OnInitDialog()rnrn CDialog::OnInitDialog();rnrn // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动rn // 执行此操作rn SetIcon(m_hIcon, TRUE); // 设置大图标rn SetIcon(m_hIcon, FALSE); // 设置小图标rnrn // TODO: 在此添加额外的初始化代码rn HANDLE m_hComm=0;rn m_hComm =CreateFile(L"COM0", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);rn if((int)m_hComm != -1)rn m_hComm =CreateFile(L"COM1", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);rn if((int)m_hComm != -1)rn m_hComm =CreateFile(L"COM2", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);rn if((int)m_hComm != -1)rn m_hComm =CreateFile(L"COM3", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);rn if((int)m_hComm != -1)rn m_hComm =CreateFile(L"COM4", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);rn if((int)m_hComm != -1)rn m_hComm =CreateFile(L"COM5", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);rn if((int)m_hComm == -1)rn MessageBox(L"COM0-COM5 Open Error!");rn elsern MessageBox(L"COM0-COM5 Open Succcess!");rnrn return TRUE; // 除非将焦点设置到控件,否则返回 TRUErn
Createfile
win CE 用Createfile 初始化的设备能用CloseHandle回收吗?rnrn好象会出错?
为什么CreateFile无法打开设备
[code=C/C++]rnvoid Cdriver_TestDlg::OnBnClickedButton4()rn rn HANDLE handle = ::CreateFile("\\\\.\\MyDeviceName",GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);rn if(handle == INVALID_HANDLE_VALUE)rn MessageBox("打开设备出错");rn CloseHandle(handle);rn rn[/code]rn一直提示打开设备出错.....请大大们帮我看下哪里写错了...rn驱动文件完整代码:rn[code=C/C++]rn#include rn#define NTSTRSAFE_LIBrn#include rnrn#define COM_DRIVER_NAME L"\\Device\\Serial0" //要绑定的设备名rn//延时用的rn#define DELAY_ONE_MICROSECOND (-10)rn#define DELAY_ONE_MILLISECOND (DELAY_ONE_MICROSECOND*1000)rn#define DELAY_ONE_SECOND (DELAY_ONE_MILLISECOND*1000)rnrnPDEVICE_OBJECT s_fltobj=NULL; //全局指针rnPDEVICE_OBJECT s_nextobj=NULL; //全局指针rnPDEVICE_OBJECT pCommunicate=NULL; //全局指针rnUNICODE_STRING devicename; //定义一个字符串rnUNICODE_STRING symboliclinkname; //定义一个字符串rnvoid ccpUnload(PDRIVER_OBJECT drv); //动态卸载函数rnNTSTATUS ccpAttachAllComs(PDRIVER_OBJECT driver); //绑定设备函数rnNTSTATUS ccpDispatch(PDEVICE_OBJECT device,PIRP irp); //自定义IRP分发函数rnNTSTATUS fengReadComplete(PDEVICE_OBJECT DeviectObject,PIRP Irp,PVOID Context); //IRP_MJ_READ回调函数rnNTSTATUS CreateDevices(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath); //创建设备用于同ring3应用程序通信rnrnNTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path) //所有的驱动都是这个入口函数跟c语言的main函数一样rn rn NTSTATUS status; //定义返回状态数据类型rn size_t i;rn status = CreateDevices(driver,reg_path);rn if (status==STATUS_SUCCESS)rn rn for(i=0;iMajorFunction[i] = ccpDispatch; //所有的分发函数都进入ccpDispatch这个函数里面去rn rn driver->DriverUnload = ccpUnload; //支持动态卸载(=号后面是卸载函数)rn ccpAttachAllComs(driver); //绑定设备rn rn return STATUS_SUCCESS; //返回成功(STATUS_SUCCESS=成功的意思)rn rnNTSTATUS CreateDevices(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)rn //创建设备用于同ring3应用程序通信rn NTSTATUS status;rn RtlInitUnicodeString(&devicename,L"\\Device\\MyDevice"); //初始化设备名称rn RtlInitUnicodeString(&symboliclinkname,L"\\??\\MyDeviceName"); //初始化符号连接名称rn status = IoCreateDevice(DriverObject,0,&devicename,FILE_DEVICE_UNKNOWN,0,FALSE,&pCommunicate); //生成设备rn if (status != STATUS_SUCCESS) //如果没有生成设备成功就返回rn return status;rn IoCreateSymbolicLink(&symboliclinkname,&devicename);//符号链接名称//设备名称rn pCommunicate->Flags |= DO_BUFFERED_IO;rn return status;rn rnvoid ccpUnload(PDRIVER_OBJECT drv) //动态卸载函数rn rn LARGE_INTEGER interval;rn UNICODE_STRING uniNtNameString; //定义一个字符串rn RtlInitUnicodeString(&uniNtNameString, COM_DRIVER_NAME); // 初始化一个字符串(就是COM驱动的名字)rn IoDetachDevice(s_nextobj); // 首先解除绑定rn interval.QuadPart = (2*1000 * DELAY_ONE_MILLISECOND); // 睡眠时间(2秒)rn KeDelayExecutionThread(KernelMode,FALSE,&interval); //等待所有irp处理结束rn IoDeleteDevice(s_fltobj); // 删除设备rn IoDeleteDevice(pCommunicate); // 删除设备rn rnNTSTATUS ccpAttachAllComs(PDRIVER_OBJECT driver) //绑定设备函数rn rn NTSTATUS status; //定义返回状态数据类型rn PFILE_OBJECT fileobj = NULL; //定义一个设备的文件对象指针rn PDEVICE_OBJECT devobj = NULL; //定义一个设备对象指针rn UNICODE_STRING uniNtNameString; //定义一个字符串rn RtlInitUnicodeString(&uniNtNameString, COM_DRIVER_NAME); // 初始化一个字符串(就是COM驱动的名字)rnrn status=IoGetDeviceObjectPointer(&uniNtNameString, FILE_ALL_ACCESS, &fileobj, &devobj); //根据设备名字获取设备对象rn if(status == STATUS_SUCCESS) //如果获取设备对象成功rn ObDereferenceObject(fileobj); //就取消设备的文件对象引用(因为过滤串口不需要文件对象)rn status = IoCreateDevice(driver,0,NULL,devobj->DeviceType,0,FALSE,&s_fltobj); //生成设备rn if (status != STATUS_SUCCESS) //如果没有生成设备就返回rn return status;rn // 拷贝重要标志位。rn if(devobj->Flags & DO_BUFFERED_IO)rn (s_fltobj)->Flags |= DO_BUFFERED_IO;rn if(devobj->Flags & DO_DIRECT_IO)rn (s_fltobj)->Flags |= DO_DIRECT_IO;rn if(devobj->Flags & DO_BUFFERED_IO)rn (s_fltobj)->Flags |= DO_BUFFERED_IO;rn if(devobj->Characteristics & FILE_DEVICE_SECURE_OPEN)rn (s_fltobj)->Characteristics |= FILE_DEVICE_SECURE_OPEN;rn (s_fltobj)->Flags |= DO_POWER_PAGABLE;rn s_nextobj = IoAttachDeviceToDeviceStack(s_fltobj,devobj); //绑定一个设备到另一个设备上rn if (s_nextobj == NULL)rn rn // 如果绑定<em>失败</em>了,销毁设备,重新来过。rn IoDeleteDevice(s_fltobj);rn s_fltobj = NULL;rn return STATUS_UNSUCCESSFUL;rn rn (s_fltobj)->Flags = (s_fltobj)->Flags & ~DO_DEVICE_INITIALIZING; //设置这个设备已经启动rn return STATUS_SUCCESS;rn rnNTSTATUS ccpDispatch(PDEVICE_OBJECT device,PIRP irp) //自定义IRP分发函数rn rn PIO_STACK_LOCATION irpsp = IoGetCurrentIrpStackLocation(irp); //获取当前栈空间rn NTSTATUS status;rn ULONG i;rn if(s_fltobj== device)rn rn if(irpsp->MajorFunction == IRP_MJ_POWER)rn rn //如果是电源直接发送,然后返回说已经被处理了rn PoStartNextPowerIrp(irp);rn IoSkipCurrentIrpStackLocation(irp);rn return PoCallDriver(s_nextobj,irp);rn rn if(irpsp->MajorFunction == IRP_MJ_WRITE)rn rn ULONG len = irpsp->Parameters.Write.Length; //获取写入数据的长度rn PUCHAR buf = (PUCHAR)irp->AssociatedIrp.SystemBuffer; //取得系统缓冲区数据rn for(i=0;iMajorFunction == IRP_MJ_READ)rn rn //因为读的是需要完成后才能得到,所以用回调函数来获取rn IoCopyCurrentIrpStackLocationToNext(irp);rn IoSetCompletionRoutine(irp, fengReadComplete, device, TRUE, TRUE, TRUE);rn return IoCallDriver(s_nextobj,irp);rn rn //其它请求直接下发(不禁止也不修改)rn IoSkipCurrentIrpStackLocation(irp);rn return IoCallDriver(s_nextobj,irp);rn rn // 如果根本就不在被绑定的设备中,那是有问题的,直接返回参数错误。rn irp->IoStatus.Information = 0;rn irp->IoStatus.Status = STATUS_INVALID_PARAMETER;rn IoCompleteRequest(irp,IO_NO_INCREMENT);rn return STATUS_SUCCESS; rn rnrnNTSTATUS fengReadComplete(PDEVICE_OBJECT DeviectObject,PIRP Irp,PVOID Context) //IRP_MJ_READ回调函数rn rn PIO_STACK_LOCATION IrpSp;rn ULONG i;rn IrpSp = IoGetCurrentIrpStackLocation(Irp);rn if(NT_SUCCESS( Irp->IoStatus.Status)) //读成功才处理rn rn PUCHAR buf = (PUCHAR)Irp->AssociatedIrp.SystemBuffer; //取得系统缓冲区数据rn for(i=0; iIoStatus.Information; i++)rn rn DbgPrint("%02X, ", buf[i]);rn rn rn if( Irp->PendingReturned)rn IoMarkIrpPending( Irp);rn return Irp->IoStatus.Status;rn rn[/code]
createfile??
我不太懂英文,谁能给我讲一下CREATEFILE这个函数呀??太谢谢了!!
CreateFile失败 GetLastError()返回5 是什么原因
我这个工程是有一个主程序 然后<em>调用</em>很多的静态库 某一个静态库中有CreateFile()rnrncmd控制台的标签显示的是 管理员: C:\Window\system32\cmd.exernUAC执行文件也改成了 requireAdministratorrnrn但是CreateFile依然<em>失败</em> GetLastError()返回5rnrn编程小白 还有很多不懂的地方 还希望大家能谅解 也同时希望大神快来指导我一下 到底是什么原因
CreateFile 打开文件重新写入失败,但GetlastError没有失败提示,
我有一颗双亲树,顺序数组存放,要保存到文件里面。每次树被更新之后就要写到文件里面去,rnrn可是下面这个函数运行没有错误,但文件总是没有得到更新rnrn[code=c]rnint PtTree::SaveToFile(LPCTSTR Filename)rnrn// ::DeleteFile(Filename);rn//情况内容,rn HANDLE hIndex = ::CreateFile(rn Filenamern ,GENERIC_WRITErn ,0rn ,NULLrn ,TRUNCATE_EXISTINGrn ,FILE_ATTRIBUTE_NORMALrn ,NULL);rnrn//打开成功但就是没有把文件更新rn if( INVALID_HANDLE_VALUE == hIndex )rn rn ShowError();rn return 0;rn rn DWORD dwNumberOfBytes;rnrn ::SetFilePointer( hIndex, 0, 0 , FILE_BEGIN );rnrn //写入节点个数rn if(0 == WriteFile( hIndex, (LPVOID) &NodeCount, sizeof(NodeCount), &dwNumberOfBytes, NULL ) )rn rn ShowError();rn CloseHandle(hIndex);rn return 0 ;rn rnrn //写入叶子节点个数rn if(0 == WriteFile( hIndex, (LPVOID)&LeafCount, sizeof(LeafCount), &dwNumberOfBytes, NULL ) )rn rn ShowError();rn CloseHandle(hIndex);rn return 0 ;rn rnrn//写入顺序树信息 ,这里在单步的时候可以看到dwNumberOfBytes为500,但文件的大小还是原来的248Brn if(NodeCount && 0 == WriteFile( hIndex, (LPVOID)( &node), (NodeCount) * sizeof(PtNode), &dwNumberOfBytes, NULL ) )rn rn ShowError();rn CloseHandle(hIndex);rn return 0 ;rn rnrn //写入叶子数组rn if(LeafCount && 0 == WriteFile( hIndex, (LPVOID)(&Leaf), (LeafCount) * sizeof(int), &dwNumberOfBytes, NULL ) )rn rn ShowError();rn CloseHandle(hIndex);rn return 0 ;rn rn rn CloseHandle(hIndex);rnrn return 1;rnrn[/code]
asp 为什么调用存储过程总是失败阿???
SQL语句rnCREATE PROCEDURE test @id int,@new varchar(40) ASrnupdate stores set stor_name=@new where stor_id=@idrnGOrnrnrnASP代码rnrnrnrn总是提示 'dd'错误rn我改为 ''dd''仍然错误rnrn请教各位!!!!
VB 调用 存储过程 sp_xml_preparedocument 为什么失败
Dim xdoc As MSXML2.DOMDocumentrnSet xdoc = New MSXML2.DOMDocumentrnDim xmlStr As Stringrnxdoc.validateOnParse = Truernxdoc.async = FalsernrnIf (xdoc.Load("D:\work\MeetingSignInFinge\excels\books.xml")) ThenrnrnxmlStr = xdoc.xmlrnMsgBox xmlStrrnElsernMsgBox xdoc.parseError.reasonrnEnd IfrnDim cmd As adodb.CommandrnSet cmd = New adodb.Commandrncmd.ActiveConnection = cnnrncmd.CommandText = "sp_xml_preparedocument" '存储过程的名称rncmd.CommandType = adCmdStoredProc '执行方式为存储过程rn'返回值参数rnSet param = cmd.CreateParameter("RetVal", adInteger, adParamReturnValue, 4)rncmd.Parameters.Append param rnrn '输出参数rnrnSet param = cmd.CreateParameter("fileNo", adInteger, adParamOutput)rn cmd.Parameters.Append paramrn'输入参数rn Set param = cmd.CreateParameter("xmldoc", adVarChar, adParamInput, 8000, straaa)rn cmd.Parameters.Append paramrn rnrn rncmd.ExecuternrnIf cmd.Parameters("RetVal").Value = 1 Thenrn MsgBox "成功"rnElsern MsgBox "<em>失败</em>"rnEnd IfrnrnrnrnrnrnSet xdoc = Nothing
为什么调用GetNetworkParams函数每次都失败
BOOL CDLGDNS::OnInitDialog() rnrn CDialog::OnInitDialog();rn rn // TODO: Add extra initialization herern FIXED_INFO* FixedInfo;rn ULONG ulOutBufLen; rn DWORD dwRetVal; rn rn FixedInfo = (FIXED_INFO*)GlobalAlloc(GPTR,sizeof(FIXED_INFO)); rn ulOutBufLen = sizeof(FIXED_INFO); rnrn char *tmpBuffer = (char *)malloc(1024);rn memset(tmpBuffer, 0, 1024);rnrn dwRetVal = GetNetworkParams(FixedInfo, &ulOutBufLen) ;rn if ( ERROR_SUCCESS != dwRetVal)rn rn m_domain.SetWindowText(_T("没有获得!"));rn m_dnsserver.SetWindowText(_T("没有获得!"));rn m_nodetype.SetWindowText(_T("没有获得!"));rn m_route.SetWindowText(_T("没有获得!"));rn m_proxy.SetWindowText(_T("没有获得!"));rn m_dns.SetWindowText(_T("没有获得!")); rn rn elsern rn m_domain.SetWindowText(FixedInfo->DomainName);rn m_dnsserver.SetWindowText(FixedInfo->DnsServerList.IpAddress.String);rn CString str1;rn str1.Format("%d",FixedInfo->NodeType);rn m_nodetype.SetWindowText(str1);rn CString str2;rn str2.Format("%d",FixedInfo->EnableRouting);rn m_route.SetWindowText(str2);rn CString str3;rn str3.Format("%d",FixedInfo->EnableProxy);rn m_proxy.SetWindowText(str3);rn CString str4;rn str4.Format("%d",FixedInfo->EnableDns);rn m_dns.SetWindowText(str4);rn rn rn //GlobalFree( FixedInfo );rn rn return TRUE; // return TRUE unless you set the focus to a controlrn // EXCEPTION: OCX Property Pages should return FALSErnrnrnrn代码如上,每次运行最后的结果都是显示的“没有获得”,怎么回事啊?
调用RegisterClass(&wc)为什么返回失败(0)?
BOOL CTempDlg::RegisterWndClass(HINSTANCE hInstance)rnrn int r;rn WNDCLASS wc;rn wc.lpszClassName = _T("GRAPH_CUSTOM"); // matches class name in clientrn wc.hInstance = hInstance;rn wc.lpfnWndProc = ::DefWindowProc;rn //wc.hCursor = LoadCursor(NULL, IDC_ARROW);rn wc.hIcon = 0;rn wc.lpszMenuName = NULL;rn wc.hbrBackground = (HBRUSH) ::GetStockObject(LTGRAY_BRUSH);rn wc.style = CS_GLOBALCLASS; // To be modifiedrn wc.cbClsExtra = 0;rn wc.cbWndExtra = 0;rn r = ::RegisterClass(&wc);rn return r;rn
为什么在SDK下调用ShowWindow(SW_HIDE);失败
我在MFC下没有问题,在SDK下rnrncase WM_PAINT:rn hdc = BeginPaint (hwnd, &ps) ;rn ShowWindow(SW_HIDE);rn EndPaint (hwnd, &ps) ;rn return 0 ;rnrn出错:error C2660: 'ShowWindow' : function does not take 1 parametersrnError executing cl.exe.
多线程中调用mapx画图失败为什么
我想将画图功能单独用一个线程来完成,可是总是<em>失败</em>,如果只用主线程则成功,<em>为什么</em>啊?以下为程序代码。rnvoid CMdiView::OnButton1() rn rn endthread=false;rn aThread=AfxBeginThread(onthread,NULL);//创建子线程rnrnrnrnUINT CMdiView::onthread(LPVOID wParam)rnrn CMdiView *ad=(CMdiView*)wParam;rn ad->dotread();rn return 0;rnrnrnvoid CMdiView::dotread(void)//子线程实现的功能,这里用setcurrenttool代替rnrn m_ctrlMapX.SetCurrentTool(miPanTool);rn rnrn结果就出现内存不能读的错误,<em>为什么</em>啊?如果不创建线程,直接<em>调用</em>dothread则没有任何问题,如果将dothread中的内容换成其他(即不<em>调用</em>MAPX的函数),也没有问题。
线程中调用全局函数失败为什么
有一个全局函数是取数据的。本来是使用定时器操作的,现在改为使用线程,但是改为线程以后<em>调用</em>全局函数就<em>失败</em>了。无法取到数据。
在DLL中调用MessageBox失败为什么
头文件如下:rnrn#ifdef FUNTYPErn#elsern #define FUNTYPE extern "C" __importrn#endifrnFUNTYPE void ShowMessage(HWND hWnd);rnrn/*mydll.cpp文件*/rnFUNTYPE void ShowMessage(HWND hWnd)rnrn MessageBox(hWnd,"测试DLL的用途","测试程序",MB_OK);rnrnrnrn然后我在Form1上放了个Button,添置如下代码:rnvoid __fastcall TForm1::Button1Click(TObject *Sender)rnrnrn typedef void (*MyFun)(HWND);rn HMODULE hMod=LoadLibrary("Mydll.dll");//刚才的DLL库名rn if(!hMod)rn rn MessageBox(Application->Handle,"载入DLL<em>失败</em>","Error",MB_OK);rn return;rn rn MyFun fun=(MyFun)GetProcAddress(hMod,"ShowMessage");rn (*fun)(Application->Handle);//若把(*fun)(Application->Handle);改为rn //fun(Application->Handle);<em>为什么</em>不报错误rn FreeLibrary(hMod);rnrn rnrn程序编译与链接没问题可招待执行出问题,<em>为什么</em>?rn错误d大致说Access violation at 000013之类的。rn
为什么调用HttpSendRequest会经常失败
我用HttpSendRequest发送http get请求,有时能成功有时会<em>失败</em>。返回的错误代码是12031,即ERROR_INTERNET_CONNECTION_RESET。rn我想问下ERROR_INTERNET_CONNECTION_RESET这个错误会在什么情况下发生。
在2K中为什么调用关机失败
在WIN2000<em>调用</em><em>为什么</em><em>失败</em>,请各位帮忙,十分感激.rnrnFUNCTION ulong ExitWindowsEx(ulong uFlags,ulong dwReserved) LIBRARY "user32.dll"rn ExitWindowsEx(1, 0)
为什么OleLoadPicture函数会调用失败
使用下面一个函数打开一幅png图像:rnrn[code=C/C++]rnstatic HBITMAP LoadAnImage(const char* FileName)rnrn // Use IPicture stuff to use JPG / GIF filesrn IPicture* p = NULL;rn IStream* s = NULL;rn IPersistStream* ps = NULL;rn HGLOBAL hG;rn void* pp = NULL;rn FILE* fp;rnrnrn // Read file in memoryrn fp = fopen(FileName,"rb");rn if (!fp)rn return NULL;rnrn fseek(fp,0,SEEK_END);rn int fs = ftell(fp);rn fseek(fp,0,SEEK_SET);rn hG = GlobalAlloc(GPTR,fs);rn if (!hG)rn rn fclose(fp);rn return NULL;rn rn pp = (void*)hG;rn fread(pp,1,fs,fp);rn fclose(fp);rnrn // Create an IStream so IPicture can rn CreateStreamOnHGlobal(hG,false,&s);rn if (NULL==s)rn rn GlobalFree(hG);rn return NULL;rn rnrn HRESULT hr = OleLoadPicture(s,0,false,IID_IPicture,(void**)&p);rnrn if (S_OK!=hr)rn rn return NULL;rn rn if (NULL==p)rn rn s->Release();rn GlobalFree(hG);rn return NULL;rn rn s->Release();rn GlobalFree(hG);rnrn HBITMAP hB = NULL;rn p->get_Handle((unsigned int*)&hB);rnrn // Copy the image. Necessary, because upon p's release,rn // the handle is destroyed.rn HBITMAP hBB = (HBITMAP)CopyImage(hB,IMAGE_BITMAP,0,0,rn LR_COPYRETURNORG);rnrn p->Release();rn return hBB;rnrnrn[/code]rnrn 但是在执行OleLoadPicture函数时<em>失败</em>,返回值是rnhr = -2146827807,16进制数就是0x800A01E1rnrn 查了一些资料:rnrnOleLoadPictureFilernrnReturn codernDescriptionrnrnS_OKrnThe method completed successfully.rnrnCTL_E_INVALIDPICTURE (0x800A01E1)rnInvalid picture file.rnrnrn <em>为什么</em>会<em>调用</em><em>失败</em>呢?如何解决?我的编译环境是:rnrnVS 2005, Win XP + sp3。rnrnrnrnrnrn rn
为什么DeviceIOControl()调用失败,返回值总是0?
我要直接用WIN32中的函数通过Windows2000提供的并口驱动程序操作专用并口设备.rn在用CreateFile("\\\\.\\LPT1",...)成功获得句柄m_hPPort(0x00000064)后,我用rnDeviceIoControl(m_hPPort,IOCTL_IEEE1284_GET_MODE,NULL,0,&OutBuffer,nOutBufferSize,&BytesReturned,NULL);读取并口工作模式,但总是<em>失败</em>,返回值为0.rn其中,PARCLASS_NEGOTIATION_MASK OutBuffer;rnnOutBufferSize = sizeof(PARCLASS_NEGOTIATION_MASK);rn紧跟其后的GetLastErro()返回值'1',表明是"Incorrect function"错误.我不明白这是什么意思.DeviceIOControl(...)的参数没有用错啊!rn先谢谢大家的帮助! rn
为什么调用这个函数失败,怎么改正?
void __fastcall TForm1::Button1Click(TObject *Sender)rnrnrnDWORD *Free;rnDWORD *Total;rnint i;rnif(GetDiskFreeSpace(NULL,NULL,NULL,Free,Total))rnrnrnEdit1->Text=IntToStr(*Free);rnEdit2->Text=IntToStr(*Total);rnrnelsernrnShowMessage("Error");rnrnrnrn
基于会员制的网络广告系统源码(MVC+JSP)下载
基于会员制的网络广告系统(MVC+JSP)。用JSP技术建立一个简单的网络广告系统,JSP引擎为Tomcat6.0,系统采用MVC模式实现各个模块,数据库连接操作使用纯JAVA驱动程序方式,本系统采用的时MySQL数据库,当然也可以使用主流的Oracle或SQL Server系列数据库,只要在代码中做部分修改就行。本资源可直接导入MyEclipse中运行,希望对初学者有一定帮助! 相关下载链接:[url=//download.csdn.net/download/myt372093898/3792690?utm_source=bbsseo]//download.csdn.net/download/myt372093898/3792690?utm_source=bbsseo[/url]
学生管理系统下载
学生管理系统 C++ 可作为项目开发,课程设计 相关下载链接:[url=//download.csdn.net/download/lxraisini/3883660?utm_source=bbsseo]//download.csdn.net/download/lxraisini/3883660?utm_source=bbsseo[/url]
VB串口通信(附图教程)下载
大家经常用的VB串口通信(附图教程),初学者的好教程。 相关下载链接:[url=//download.csdn.net/download/fenguiqing/4660116?utm_source=bbsseo]//download.csdn.net/download/fenguiqing/4660116?utm_source=bbsseo[/url]
相关热词 c#异步发送kafka c#窗体编号 c# 操作二进制文件 c# 反射 机制 c#线程 窗体失去响应 c#角度转弧度 c# 解析gps数据 c# vs设置 语法版本 c# json含回车 c#多线程demo
我们是很有底线的