Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
Edited 9-May-12 21:34pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

CreateFile function[^]
There you'll find examples.
  Permalink  
Comments
Manoj Patter at 10-May-12 3:35am
   
sir
i used it all.....
losmac at 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 at 11-May-12 1:24am
   
sir i have created handle, thanks alot
but i am facing a problem again
Rate this: bad
good
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
 

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
  Permalink  
Comments
Andy411 at 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)



Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 11 May 2012
Copyright © CodeProject, 1999-2014
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