Click here to Skip to main content
15,886,807 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i had tried this way

VB
<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


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
Posted
Updated 9-May-12 21:34pm
v2

CreateFile function[^]
There you'll find examples.
 
Share this answer
 
Comments
Manoj Patter 10-May-12 3:35am    
sir
i used it all.....
Maciej Los 10-May-12 5:02am    
Please, clarify your question. Does the application return some error? What kind of error, what kind of message?
Can't you use Image class?
Manoj Patter 11-May-12 1:24am    
sir i have created handle, thanks alot
but i am facing a problem again
VB
<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

.....
........
VB
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



VB
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)



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
 
Share this answer
 
Comments
Andy411 11-May-12 2:14am    
What do you mean with "using in loop"?

1) Of course you cannot call this function repeatedly with the same filename. It has to fail, becaus the file is allready open.
Do not forget to close your file with CloseHandle()

2) Try GetLastError() to examine, why the function fails.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900