要导入kernel32的createfile [英] want to import createfile of kernel32

查看:567
本文介绍了要导入kernel32的createfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过这种方式

i had tried this way

<DllImport("kernel32.dll")> _
Shared Function CreateFile(Byval strPathName As String,Byval iDesiredAccess As UInteger, ByVal iShareMode As UInteger, ByRef pSecurityAttributes As IntPtr, Byval iCreationDisposition As UInteger, Byval iFlagsAndAttributes As UInteger, ByRef hTemplateFile As IntPtr) As IntPtr
    End Function



然后使用createfile作为

hfile = CreateFile("C:\ photo.jpg",2147483648,1,IntPtr.Zero,3,128,IntPtr.Zero)

但这无法创建"photo.jpg"的句柄并返回-1 ...

那我该怎么做才能做到这一点..........

感谢advance



and then use createfile as

hfile = CreateFile("C:\photo.jpg", 2147483648, 1, IntPtr.Zero, 3, 128, IntPtr.Zero)

But this cant create handle of "photo.jpg" and return -1...

then anything what i could do to get this..........

Thanks advance

推荐答案

CreateFile function[^]
There you''ll find examples.


<DllImport("kernel32.dll")> _
    Public Shared Function CreateFile(ByVal strPathName As String, ByVal iDesiredAccess As Int32, ByVal iShareMode As Int32, ByRef pSecurityAttributes As IntPtr, ByVal iCreationDisposition As Int32, ByVal iFlagsAndAttributes As Int32, ByRef hTemplateFile As IntPtr) As IntPtr

    End Function


.....
........


.....
........

Const GENERIC_READ = &H80000000
        Const GENERIC_WRITE = &H40000000
        Const OPEN_EXISTING = 3
        Const CREATE_ALWAYS = 2
        Const FILE_SHARE_READ = &H1
        Const FILE_SHARE_WRITE = &H2
        Const FILE_ATTRIBUTE_NORMAL = &H80







sfile_handle = CreateFile(sfileinfo.FullName, GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
                    store_handle = CreateFile("D:\FileName", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)

br/>

这将返回句柄作为整数值.
但是当我在循环中使用这个
sfile_handle返回-1,store_handle返回任何整数...

这个问题真是个问题..... plz帮助




this returns handle as integer value.
But when i am using this in for Loop
sfile_handle return -1 and store_handle return any integer...

What a prob with this.....plz help


这篇关于要导入kernel32的createfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆