Closing a Mutex Handle

Pages: 12
Ok so I think I finally understand this all, thanks to everyone that's bothered to help me as slow as I am...

Here's my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "stdafx.h"
#include "Form1.h"
#include <Windows.h>
#include <iostream>

using namespace Extension1;
using namespace std;

void printerror(LPSTR location){
    printf("Error: %s_%d", location, GetLastError());
    cin.get();
}

int main(){
    DWORD pid = 0;
    HWND hMineWnd = FindWindow("RumbleFighter", "RumbleFighter");
    GetWindowThreadProcessId(hMineWnd, &pid);
    HANDLE hProc =OpenProcess(PROCESS_DUP_HANDLE, 0, pid);
    if(hProc == NULL){
        printerror("1");
        return 1;
    }
    HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, "wpavkdlxjabxprtm");
    if(hMutex == NULL){
        printerror("2");
        return 2;
    }
    if(DuplicateHandle(hProc, hMutex, NULL, 0, 0, FALSE, DUPLICATE_CLOSE_SOURCE) == 0){
        printerror("3");
        return 3;
    }
    if(CloseHandle(hMutex) == 0){
        printerror("4");
        return 4;
    }
    return 0;
}


I've been trying to compile it though I get these errors

1
2
3
4
5
6
7
8
9
10
1>Extension 1.obj : error LNK2028: unresolved token (0A00001E) "extern "C" unsigned long __stdcall GetWindowThreadProcessId(struct HWND__ *,unsigned long *)" (?GetWindowThreadProcessId@@$$J18YGKPAUHWND__@@PAK@Z) referenced in function "int __clrcall main(void)" (?main@@$$HYMHXZ)

1>Extension 1.obj : error LNK2028: unresolved token (0A00001F) "extern "C" struct HWND__ * __stdcall FindWindowA(char const *,char const *)" (?FindWindowA@@$$J18YGPAUHWND__@@PBD0@Z) referenced in function "int __clrcall main(void)" (?main@@$$HYMHXZ)

1>Extension 1.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall GetWindowThreadProcessId(struct HWND__ *,unsigned long *)" (?GetWindowThreadProcessId@@$$J18YGKPAUHWND__@@PAK@Z) referenced in function "int __clrcall main(void)" (?main@@$$HYMHXZ)

1>Extension 1.obj : error LNK2019: unresolved external symbol "extern "C" struct HWND__ * __stdcall FindWindowA(char const *,char const *)" (?FindWindowA@@$$J18YGPAUHWND__@@PBD0@Z) referenced in function "int __clrcall main(void)" (?main@@$$HYMHXZ)

1>c:\users\owner\documents\visual studio 2010\Projects\Extension 1\Debug\Extension 1.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


The form this is being driven from is a simple one with a rich-text box and pointer reader, nothing complex. It's set so upon the opening of the form the handle should be duplicated then shut at it's handle source.
Last edited on
Are you linking with kernel32.lib and user32.lib?

BTW, take a look at these:
RemoteExecute
http://help.madshi.net/RemoteExecute.htm

Closing a handle of another process
http://forum.madshi.net/viewtopic.php?t=217

These describe what you need to do. They don't supply an implenentation for RemoteExecute, but there is a description of how it might be implemented. I think ne55 had some posts about using hooks to run code in another process, but finding old posts on the forum isn't that easy.
Last edited on
Thank you so much... I finally completed it.
Topic archived. No new replies allowed.
Pages: 12