|
|
Comments and Discussions
|
|
 |

|
Dear Naveen,
Please Describe this
"Recompile the code and change the calling convention to __stdcall
2) create another c/c++ dll in which there should be a function that call GetOpenedFiles internally. Also you need to export this function in the new with __stdcall calling convention.
I hope you know how to call a C function from vb6."
I am not good in c/C++ and need to implement in VB.Net
Thank you in Advance
Yashvi
|
|
|
|
|

|
Hi,
Great work! I do have a question though:
I have two machines running Win7 Ultimate. Both are up-to-date. On one machine, OpenFileFinder.exe properly displays a file that I opened in another application. On the other machine it cannot find the open file. It looks like process information is missing on one machine. I do not see how that is possible. Wondering if there is some Operating System setting that I don't know about.
I am the author of the "IP Camera Filter" which is a DirectShow Video Source filter. During reinstallation of our software, we need to delete old filters and install new ones on a user's machine. We discovered that SKYPE unaccountably opens our filters and leaves them open even though SKYPE is not using them. Our installation software can then not delete the filters that it needs to delete. I would like to show the name of the program that is holding our files open to the user so he can close whatever process is locking our files. It looks like I can do that on one of my machines but not the other and I don't understand why. I need this to work reliably on any user's machine...
Strangely enough, if I use an Explorer window and go to the directory where our locked file is and use Explorer to right-click on the file and "delete" the file, it pops up a "File in Use" window that shows the process that is locking our file. This works on both machines...
Would appreciate any suggestions you might have.
Thanks,
Howard
Howard C. Anderson
HTTP://www.astroshow.com
|
|
|
|

|
Thanks.
For your problem, I am not sure excatly whats happening, but the first thing we can suspect is the driver installation on the 2nd box. May be it is failing while installing the driver. To find this out, you can go to your "C" drive and take the "List opened files" and then when the dialog comes up, right click on it and select "Show Loaded files only" option. If any this is listed in the dialog, the driver installation is fine.
I will help you to track down the problem furter after this..
|
|
|
|

|
Hi Nave, Thanks very much for responding. I did what you asked on the machine that is not showing the locked file I am looking for. A box came up that said "The Full Count = 5170". I hit OK. "Dialog" window came up. Lots of processes listed. I right-clicked in the ComboBox area and selected "Show Opened Files Only" (There was no "Show Loaded files only" item.) Again, the "Dialog" ComboBox listed a lot of files but the one I locked was not there. Neither was there ANY reference to the program that I invoked to lock the file (HandyAvi).
On the OTHER machine I do NOT get a box saying "The Full Count...". The initial list is much longer. I see my application and it has LOTS of processes listed including the file that it has opened and that is locked. When I select "Show Opened Files Only", the list showing my application is shorter and does NOT contain the file that it has locked/open.
The machine where it is failing has LOTS of processes running. I wonder if there is some limit? I have not yet figured out a way to see where you are entering data into your ComboBox. ComboBox can hold only 65536 items. I doubt that we are overflowing that but I would need to insert a counter to be sure...
Thanks,
Howard
http://www.azcendant.com
http://www.astroshow.com
Howard C. Anderson
HTTP://www.astroshow.com
|
|
|
|

|
Howard Anderson wrote: "The Full Count = 5170".
This is bit strange. Not sure who is showing this dialog. I will check this after I get home. BTW you mean ListBox right, not ComboBox
Howard Anderson wrote: When I select "Show Opened Files Only", the list showing my application is
shorter and does NOT contain the file that it has locked/open.
That means the locked files is loaded a module rather than, the process opening it as file. So may be OpenFileFinder failed to open the process and enumerate because of some permission issue. Does the machines have some difference in the UAC? I mean UAC is disabled in one machine or something like that?
|
|
|
|

|
Hi Nave,
Near as I can tell, UAC settings are identical. (I typed UAC into "Windows Help and Support" and followed the instructions on both machines to look at Local Policies->Security Options->User Account Control. There were 10 UAC settings. All settings were identical.)
Line 14 of your MainDlg.h defines "CCombobBox m_combobox". I think you are using a ComboBox for listing results. I see no reference in your code to a ListBox.
Thanks,
Howard
Howard C. Anderson
HTTP://www.astroshow.com
|
|
|
|
|

|
Hi Nave,
Not sure which mailbox you mean or what you want me to check for.
I have ruled out ComboBox limitations. I put some code in to directly check for a locked file when you store the data in OnFileFound. I put this code:
CStringA theText;
theText = CStringA(OpenedFileInfo.lpFile) + CStringA("\n");
CStringA myText;
myText = CStringA("ipcamfilter");
if(theText.Find(myText) > -1){
int iii = 0;
}
right after your code:
// Insert Process name, PID and file name
m_list.InsertItem( m_nCount, stInfo.csProcess, stInfo.dwImageListIndex );
CString csPid;
csPid.Format( _T("%d ( 0x%x )"), OpenedFileInfo.dwPID , OpenedFileInfo.dwPID );
m_list.SetItemText( m_nCount, 1, csPid );
m_list.SetItemText( m_nCount, 2, OpenedFileInfo.lpFile );
m_list.SetItemData( m_nCount, (DWORD_PTR)OpenedFileInfo.hFile );
m_nCount++;
and I set a break on the line containing iii.
It found the locked file on one machine but not on the other...
Most puzzling... Somehow one machine is preventing your code from finding my process information. But I don't see how. I think this is not a problem with your code but somehow a problem with something in the setup of the operating system. Have no idea what or where to look at the moment. (The Explorer window's "delete" function always seems to find the process that is locking my file. Wish I could figure out how to call that from my code. I just want to provide the user the information of what process is locking our files to make it easier for the user to locate and correct the problem if it occurs... Calling the Explorer window's "delete" function would be a good alternative if I could figure out a way to access it...)
Thanks,
Howard
Howard C. Anderson
HTTP://www.astroshow.com
|
|
|
|

|
Howard Anderson wrote: Not sure which mailbox you mean or what you want me to check for.
I took the email option below the post. It might have sent to the email you configured in Code project. Thought to take this chat offline
Can I try installing your application in my machine and see whether it is able to find out the process or not? If yes, please give me the steps. You can mail me details to nave432@gmail.com .
|
|
|
|

|
Hi,
could you or someone else maybe please compile the source as a managed .net c++ dll?
with visual studio 2008 or 2010.
.Net Framework version is not relevant.
But it should be 32 bit and not 64 bit.
thnx and kind regards
Steven
|
|
|
|

|
you can call the C++ interface directly from you managed code..
|
|
|
|

|
Good stuff
|
|
|
|
|

|
What is the bObjectType value for com port type of handle? Thanks
|
|
|
|

|
Can you tell me through which API's you created those handle. An easy way to find out is to run the process explorer and in the "handles view" check the name and type. This values might changes from OS to OS.
|
|
|
|

|
Hi nave,
I was using the NtQuerySystemInformation. I was very much trying to modify your code so that i can retrieve the handles that are associated with com ports.
I am on 64-bit Windows 7.
Thanks
- ter
|
|
|
|

|
terenceljy wrote: I was using the NtQuerySystemInformation
No I mean, I am not sure which API creates com ports handle. Like CreateFile create file handle, which API creates com port handle?
|
|
|
|

|
hi naveen first of all thank u very much for your code.. i have an issue your code not support swf shock wave file....when swf file is runing its shows all used file but not show swf file how to detect currently used swf file
|
|
|
|

|
Can you tell me which application is playing the swf file? if the application has a file opened for the swf file, it should have been displayed. Anyway let me know which application you are talking about.
|
|
|
|
|

|
Okey. I will check this application once I get back to home.
|
|
|
|

|
I checked the application, there are two things I noted
1) when u launch the applicaion, it lauches a child process also which is actually the one that opens the swf file and plays the video.
2) For small swf/flv files it open the file and close the file immediately. So you wont be able to see it, unless u are lucky to run the openfilefinder between that small time frame.
|
|
|
|

|
I NOTICED ONE THING IF CURRENT PLAY SWF FILE TRYING TO DELETE..ITS DELETED WITHOUT ANY MESSAGE LIKE FILE IN USE.PLEASE CHECK THIS.. ANY OTHER SOLUTION TO GET SWF FILE NAME
|
|
|
|

|
ddddassa wrote: I NOTICED ONE THING IF CURRENT PLAY SWF FILE TRYING TO DELETE..ITS DELETED
WITHOUT ANY MESSAGE LIKE FILE IN USE
Yeah. it is because the application has already closed all the handles to the file, so it is free to delete the file.
ddddassa wrote: ANY OTHER SOLUTION TO GET SWF FILE NAME
I dont see any other way to get the current playing file name from it. But ofcourse like i said before, if the file size is big, you can get the file name.
|
|
|
|

|
PLEASE EXPLAIN HOW TO USE GETOPENEDFILES FUNCTION IN VB6
|
|
|
|

|
Unfortunatly while I releasing this project, I forgot to change the calling convention of GetOpenedFiles to __stdcall. Currently it is following __cdecl calling convention, and AFAIK there is no way to call this method directly from VB6.
How ever, what you can do is,
1) Recompile the code and change the calling convention to __stdcall
2) create another c/c++ dll in which there should be a function that call GetOpenedFiles internally. Also you need to export this function in the new with __stdcall calling convention.
I hope you know how to call a C function from vb6.
In the next release I will change the calling convention to __stdcall.
|
|
|
|

|
mr naveen u done an excellent job please help me how to use these function in vb6
|
|
|
|

|
Please see my answer to above post..
|
|
|
|

|
hi naveen thank u very much for your quick response i want to know how to handle if media player track change i m using timer to check every 5 seconds media player track change or not but first timer check all my hard drive. it take long time.. please give me any solution..if media player title change then automatically call this function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim proces As String = processids()
For Each myDrive In allDrives
GetOpenedFiles(myDrive.Name, 3, AddressOf MyCallBack, 0)
Next
End Sub
|
|
|
|

|
no.. you dont have to do like that. If you want to check in all drives, just specify the first parameter as empty string
GetOpenedFiles("", 3, AddressOf MyCallBack, 0);
|
|
|
|

|
but sir if media player play f:\track1.mpg getopenfile show filename f:\track1.mpg after 5 seconds timer works again GetOpenedFiles("", 3, AddressOf MyCallBack, 0) now first it check drive c:\ d:\ e:\ and after that it check f:\track1 it take a long time
|
|
|
|

|
thats not the way this application works. It does not go through all the files in the disk. it just returns the name of files kept opened by the process. this information is fetched from OS memory not from disk drive. you can make this faster but might need to change the source code of this application. Now this application will check for opened files in all process, instead, it can check for the files opened by the specified process ID. check the EnumerateOpenedFiles function in the dll.
Let me see.. I will modify the application and post a new one in near future. Also if you want please go ahead and modify the code..
|
|
|
|
|

|
hi i want get current media player file name in current running process here is my code please check
Imports System.Runtime.InteropServices
Public Class Form1
Public Delegate Sub CallBackFuncDef(ByVal fileinfo As OF_INFO_t, ByVal context As IntPtr)
Structure OF_INFO_t
Dim processid As Integer
Dim filename As String
Dim handlevalue As IntPtr
End Structure
Shared Sub GetOpenedFiles(ByVal path As String, ByVal Filter As Integer, ByVal CallBackProc As CallBackFuncDef, ByVal pUserContext As IntPtr)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim proces As String = processids()
GetOpenedFiles("e:\", 1, AddressOf MyCallBack, proces)
End Sub
Private Sub MyCallBack(ByVal fileinfo As OF_INFO_t, ByVal context As IntPtr)
MsgBox(fileinfo.filename & fileinfo.processid)
End Sub
Public Function processids()
Try
Dim pid As Integer = 0
Dim filename As String = Nothing
Dim mysession As Integer = 0
' Get the session ID for the current process
Using currentProcess As Process = Process.GetCurrentProcess()
mysession = currentProcess.SessionId
End Using
' Find the matching ehshell process in the same session
For Each proc As Process In Process.GetProcessesByName("wmPlayer")
If proc.SessionId = mysession Then
pid = proc.Id
End If
proc.Dispose()
Next
' Check we found a process, if not, abort
If pid = 0 Then
Trace.TraceWarning("No wmplaye process found")
' Return
End If
Return pid
Catch ex As Exception
End Try
End Function
End Class
|
|
|
|

|
in the call back function you can check the fileinfo.processid with the PID of wmplayer and if it matches you can check whether the file is a media file or not (probably by examining the extension).
Private Sub MyCallBack(ByVal fileinfo As OF_INFO_t, ByVal context As IntPtr)
if( fileinfo.processid = WmPlayerPID )
{
}
End Sub
|
|
|
|

|
I am writing a VB where i need to be able to see which of the 2 processes i open owns certain files in a directory. I played with this as much as i could, but cannot figure out everything i need. I was able to use the C# code posted to use the DLL but that function is limited.
Is there a reference somewhere that I am missing?
|
|
|
|

|
Are you using plain VB or VB.net. I have posted the code to use the dll in vb.net here[^]
|
|
|
|

|
Hi,
Before going to the bad things...great tutorial.
The only working resource I found on the web for this problem.
However, I need to detect whether some .NET services are holding some DLLs.
When running the code on a simple process it works great.
Once I run the process as a service it is no longed detected by the code.
Any idea?
|
|
|
|

|
Can you give me a little more description...You are calling the function from a service?
From what I understood you are trying to find out the file kept open by a .net service right?But for that it is not necessary to run this application from a service..isnt it?
The services usually doesnt have much privilages.. so not sure which all API's fails when u call it from service.. have u debugged it?
|
|
|
|

|
Private Const DUPLICATE_SAME_ACCESS As Long = &H2
Private Const DUPLICATE_CLOSE_SOURCE As Long = &H1
Private Const STATUS_INFO_LENGTH_MISMATCH As Long = &HC0000004
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Private Const FILE_MAP_READ As Long = &H4
Private Const PAGE_READONLY As Long = &H2
Private Const HEAP_ZERO_MEMORY As Long = &H8
Private Const TOKEN_ADJUST_PRIVILEGES As Long = &H20
Private Const SE_PRIVILEGE_ENABLED As Long = &H2
Private Const SE_PRIVILEGE_NAME As String = "SeDebugPrivilege"
Private Const TOKEN_QUERY As Long = &H8
Private Const SystemHandleInformation As Long = &H10
Private Type SYSTEM_HANDLE_INFORMATION
ProcessID As Long
ObjectTypeNumber As Byte
Flags As Byte
Handle As Integer
Object_Pointer As Long
GrantedAccess As Long
End Type
Private Type LUID
LowPart As Long
HighPart As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
LuidUDT As LUID
Attributes As Long
End Type
Private Declare Function GetProcessHeap Lib "kernel32.dll" () As Long
Private Declare Function HeapAlloc Lib "kernel32.dll" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32.dll" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal lpMem As Long) As Long
Private Declare Function HeapDestroy Lib "kernel32.dll" (ByVal hHeap As Long) As Long
Private Declare Function NtQuerySystemInformation Lib "ntdll.dll" (ByVal SystemInformationClass As Long, ByVal pSystemInformation As Long, ByVal SystemInformationLength As Long, ByRef ReturnLength As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function DuplicateHandle Lib "kernel32.dll" (ByVal hSourceProcessHandle As Long, ByVal hSourceHandle As Long, ByVal hTargetProcessHandle As Long, ByRef lpTargetHandle As Long, ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwOptions As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function CreateFileMappingW Lib "kernel32" (ByVal hFile As Long, ByVal lpFileMappigAttributes As Long, ByVal flProtect As Long, ByVal dwMaximumSizeHigh As Long, ByVal dwMaximumSizeLow As Long, ByVal lpName As String) As Long
Private Declare Function MapViewOfFile Lib "kernel32" (ByVal hFileMappingObject As Long, ByVal dwDesiredAccess As Long, ByVal dwFileOffsetHigh As Long, ByVal dwFileOffsetLow As Long, ByVal dwNumberOfBytesToMap As Long) As Long
Private Declare Function GetMappedFileNameW Lib "Psapi.dll" (ByVal hProcess As Long, ByVal lpv As Long, ByVal lpFileName As Long, ByVal nSize As Long) As Long
Private Declare Function UnmapViewOfFile Lib "kernel32" (ByVal lpBaseAddress As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValueA Lib "advapi32" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As Any, ReturnLength As Any) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Sub RtlZeroMemory Lib "kernel32.dll" (Destination As Any, ByVal Length As Long)
Private Declare Function GetModuleFileNameExW Lib "Psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As Long, ByVal nSize As Long) As Long
Dim HandleInfo() As SYSTEM_HANDLE_INFORMATION
Dim m_cHandles As Long
Dim hProcess As Long
Dim hHandle As Long
Dim szName As String
Dim szAppName As String
Public Sub QueryHandlesBuffer()
Dim lpBufferHandles As Long
Dim Length As Long
Dim ret As Long
Dim n As Long
Length = &H100
lpBufferHandles = HeapAlloc(GetProcessHeap, HEAP_ZERO_MEMORY, Length)
If lpBufferHandles = 0 Then
Exit Sub
End If
While (NtQuerySystemInformation(SystemHandleInformation, lpBufferHandles, Length, ret) = STATUS_INFO_LENGTH_MISMATCH)
Length = Length * 2
HeapFree GetProcessHeap, 0, lpBufferHandles
lpBufferHandles = HeapAlloc(GetProcessHeap, HEAP_ZERO_MEMORY, Length)
Wend
If lpBufferHandles = 0 Then
Exit Sub
End If
m_cHandles = ReadLong(lpBufferHandles)
ReDim HandleInfo(m_cHandles) As SYSTEM_HANDLE_INFORMATION
RtlZeroMemory HandleInfo(0), LenB(HandleInfo(0)) * m_cHandles
RtlMoveMemory HandleInfo(0), ByVal lpBufferHandles + 4, LenB(HandleInfo(0)) * m_cHandles
HeapFree GetProcessHeap, 0, lpBufferHandles
For n = 0 To m_cHandles - 1
If HandleInfo(n).ObjectTypeNumber = 28 Then OpenProcessForHandle HandleInfo(n).ProcessID
DuplicateHandle hProcess, HandleInfo(n).Handle, GetCurrentProcess, hHandle, 0, 0, DUPLICATE_SAME_ACCESS
If hHandle <> 0 Then
szName = GetObjectName(hHandle)
szAppName = GetProcessName(hProcess)
If LenB(szName) > 0 Then
If InStr(1, szName, ".tax", vbTextCompare) > 0 Then
List1.AddItem "hProcess = " & hProcess
List1.AddItem "File = " & szName
List1.AddItem "Process = " & szAppName
List1.AddItem "handle= " & HandleInfo(n).Handle
List1.AddItem HandleInfo(n).ProcessID
End If
End If
CloseHandle hHandle
End If
End If
Next n
End Sub
Private Function GetObjectName(ByVal dwHandle As Long) As String
Dim hFileMap As Long
Dim pMem As Long
Dim cbLength As Long
Dim bName(8192) As Byte
hFileMap = CreateFileMappingW(dwHandle, 0, PAGE_READONLY, 0, 1, 0)
If hFileMap = 0 Then
Exit Function
End If
pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1)
If pMem = 0 Then
CloseHandle hFileMap
Exit Function
End If
cbLength = GetMappedFileNameW(GetCurrentProcess, pMem, VarPtr(bName(0)), 8192)
If cbLength <> 0 Then
GetObjectName = Left$(bName, cbLength)
Else
GetObjectName = vbNullString
End If
CloseHandle hFileMap
UnmapViewOfFile pMem
Erase bName
End Function
Private Function GetProcessName(ByVal dwProcess As Long) As String
Dim bProcess(8192) As Byte
Dim cbLength As Long
cbLength = GetModuleFileNameExW(dwProcess, 0, VarPtr(bProcess(0)), 8192)
If cbLength <> 0 Then
GetProcessName = Left$(bProcess, cbLength)
Else
GetProcessName = vbNullString
End If
Erase bProcess
End Function
Private Sub OpenProcessForHandle(ByVal ProcessID As Long)
Dim LastPID As Long
If ProcessID <> LastPID Then
CloseHandle hProcess
hProcess = OpenProcess( _
PROCESS_ALL_ACCESS, _
0, _
ProcessID)
LastPID = ProcessID
End If
End Sub
Public Sub SeDebugPrivilege()
Dim Success As Long
Dim hToken As Long
Dim TokenPriv As TOKEN_PRIVILEGES
Success = OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hToken)
Success = LookupPrivilegeValueA(vbNullString, SE_PRIVILEGE_NAME, TokenPriv.LuidUDT)
TokenPriv.PrivilegeCount = 1
TokenPriv.Attributes = SE_PRIVILEGE_ENABLED
Success = AdjustTokenPrivileges(hToken, 0, TokenPriv, 0, ByVal 0&, ByVal 0&)
CloseHandle hToken
End Sub
Private Function ReadLong(ByVal Ptr As Long) As Long
Dim Bogus As Long
RtlMoveMemory Bogus, ByVal Ptr, 4
ReadLong = Bogus
End Function
this is working fine in xp but.. not workin in vista!!
Can u tell why?
|
|
|
|
|
|

|
Hello,
I found that each new call takes more and more time on Windows7, 64bit.
Can be easily reproduced using demo app: just press refresh right after list is refreshed - first time it takes <10 sec, after a couple of attempts - more than 1 min.
Is there any way to avoid this problem?
|
|
|
|

|
sry.. I dont have a windows 7 64 bit to test now. Hope you have read the section "The Problem with Vista 64 Bit and Windows-7 64 Bit" in this article. Since my driver is not digitally signed, i cant get it installed in windows 7 machine. Optionally u can modify your windows setting to allow load unsigned driver. But if you going to distibute your application, each customer have to do the same.. Or you can sent this driver to microsoft and get it digitally signed.
Anyway I will try to simulate this problem in 32 bit and update you..
|
|
|
|

|
Hi guys,
I've tried to use external dll for my application.
I attach my very simple code:
namespace Open64
{
class Program
{
public Program()
{
GetOpenedFiles("C:\\", OF_TYPE.ALL_TYPES, CallbackFunction, UIntPtr.Zero);
}
//void GetOpenedFiles(LPCWSTR lpPath, OF_TYPE Filter, OF_CALLBACK CallBackProc, UINT_PTR pUserContext);
public enum OF_TYPE : int
{
FILES_ONLY = 1,
MODULES_ONLY = 2,
ALL_TYPES = 3
}
public struct OF_INFO_t
{
Int32 dwPID;
String lpFile;
IntPtr hFile;
}
public delegate void CallbackFunctionDef(OF_INFO_t info, IntPtr context);
[DllImport("OpenFileFinder.dll", EntryPoint = "GetOpenedFiles")]
static extern void GetOpenedFiles(string lpPath, OF_TYPE filter, CallbackFunctionDef CallBackProc, UIntPtr pUserContext);
public void CallbackFunction(OF_INFO_t info, IntPtr context)
{
Console.WriteLine("asd");
}
[STAThread]
static void Main()
{
new Program();
}
}
}
But GetOpenedFiles never invoke my CallbackFunction. How can I solve?
|
|
|
|

|
I am not sure, but i think it might be because of some missing attribute you forgot to mention in dll import such as calling convention and char set.
Please check the below thread, I have posted some code to use in vb.net. Set all the attibutes i specified for the structure and the import function.
Usage in vb.net[^]
|
|
|
|

|
Hello
I'm trying to use your method GetOpenedFiles and I have one question: is there any way to stop the process of finding files?
This method calls callBack function undefined amount of times and I need to stop this process when specific file is found.
Or hopefully there is some easier way to get the list with all opened files then just wait for some hardcoded time and create the list inside Callback function?
|
|
|
|

|
Your use case is a valid one. But unfortunatly this application doesn't support such a mechanism. But ofcourse this application is open, so free feel to modify the code. I will also try to update this in future release.
abxd wrote: Or hopefully there is some easier way to get the list with all opened files
There are some techincal difficulties in returning back a list of file names, for instace the calling application doesnt know, how big the array should be. Also I cannot use any list or array classes in interface, cause this interface is supposed to be C interface, so that it can be called from .net or VB or other type of applications. Let me know if you have any thing in mind to make such an interface...
|
|
|
|

|
I have created test application in VB.Net using instruction from comments to this article. I found that
GetOpenedFiles(SearchPath, OF_TYPE.ALL_TYPES, AddressOf MyCallBack, 0)
for values of OF_TYPE = 2,3 returns only modules (files with extensions .exe, .dll, .ime, .drv, .rll, .acm, .odf, .cpl, .ocx, .tsp, .scr, .api), ignoring opened files of types .txt, .docx, .xlsx, .pdf. When using OF_TYPE.FILES_ONLY = 1 it finds nothing. As demo application shows those files seems that I do something wrong.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
A ShellExtension that lists all the used files in a folder.
| Type | Article |
| Licence | CPOL |
| First Posted | 28 May 2007 |
| Views | 211,139 |
| Downloads | 8,331 |
| Bookmarked | 183 times |
|
|