Click here to Skip to main content
12,894,219 members (53,006 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
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

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 4-May-12 0:30am
Updated 9-May-12 21:34pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

CreateFile function[^]
There you'll find examples.
Manoj Patter 10-May-12 3:35am
i used it all.....
losmac 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
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

<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

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 11 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100