?
Solved

Plz Help / Calling external DLL

Posted on 2008-10-19
3
Medium Priority
?
444 Views
Last Modified: 2008-11-14
Hi ! How to add a reference to the third party dll in the class ? can you please let me know by coding ..thanks
0
Comment
Question by:s_maha1978
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:wwnosal
ID: 22752337
0
 

Author Comment

by:s_maha1978
ID: 22752380
Hi THANKS< instead of dll importhow can reference that dll without adding to my current project. I mean like is there anything like Load library methods ??
0
 

Accepted Solution

by:
Hipposaver earned 750 total points
ID: 22801647
its called "Dll Injection" heres a code; usage
MsgBox LoadDLL(DLLPath.text, ProcessName.text)

modules:
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal fAllocType As Long, FlProtect As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal ProcessHandle As Long, lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Any, ByVal lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
 
Private Const MEM_COMMIT As Long = &H1000
Private Const PAGE_READWRITE As Long = &H4
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Private Const TH32CS_SNAPPROCESS As Long = &H2
Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const SYNCHRONIZE As Long = &H100000
Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
 
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "USER32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
 
Private Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szExeFile As String * 260
End Type
 
 
Private Function LoadDLL(DLLPath As String, EXEName As String) As Integer
Dim hAlloc As Long, hProcID As Long, hInject As Long, hLL As Long, hThread As Long
hProcID = GetProcID(EXEName)
hAlloc = VirtualAllocEx(hProcID, ByVal 0, Len(DLLPath), MEM_COMMIT, ByVal PAGE_READWRITE)
If hAlloc Then
    hInject = WriteProcessMemory(hProcID, hAlloc, ByVal DLLPath, Len(DLLPath), 0)
    If hInject Then
        hLL = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA")
        If hLL Then
            hThread = CreateRemoteThread(hProcID, 0, 0, hLL, hAlloc, 0, 0)
            If hThread = 0 Then
                LoadDLL = 1
            End If
        Else
            LoadDLL = 2
        End If
    Else
        LoadDLL = 3
    End If
Else
    LoadDLL = 4
End If
End Function
 
Public Function GetProcID(ByVal EXEName As String) As Long
Dim sEName() As String
Dim f As Long, sName As String
Dim hSnap As Long, proc As PROCESSENTRY32, hProc As Long, proc1 As PROCESSENTRY32
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
IsRunning = False
proc.dwSize = Len(proc)
If hSnap <> 0 Then
    f = Process32First(hSnap, proc)
    Do While f
        sName = Left$(proc.szExeFile, InStr(1, proc.szExeFile, Chr(0)) - 1)
        sEName = Split(sName, "\")
        sName = sEName(UBound(sEName))
        If LCase(sName) = LCase(EXEName) Then 'lcase() for NOT case sensitive
            GetProcID = OpenProcess(PROCESS_ALL_ACCESS, False, proc.th32ProcessID)
            Exit Function
        End If
        f = Process32Next(hSnap, proc)
    Loop
End If
End Function

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question