| View previous topic :: View next topic |
| Author |
Message |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Wed Dec 22, 2010 11:51 am Post subject: [C++] Help with a little code please? |
|
|
Thanks for the help with the previous problem.
This one is another one...
I dont get why this is happening...
I need it working so then I can call Test(); to initialize the form
test.cpp
| Code: | #include "Test.h"
#pragma managed(push, off)
void WINAPI MyThread ()
{
MessageBox(NULL, L"Ok Injected", L"Testing", MB_OK | MB_ICONWARNING | MB_SETFOREGROUND);
}
#pragma managed(push, off)
bool WINAPI DllMain ( HMODULE hModule, DWORD dwReason, LPVOID lpvReserved )
{
switch ( dwReason ) {
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
if ( CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MyThread, NULL, 0, NULL) == NULL ) {
return FALSE;
}
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
|
test.h
| Code: | #pragma once
#include <windows.h>
namespace ThisThing {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Test
/// </summary>
public ref class Test : public System::Windows::Forms::Form
{
public:
Test(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Test()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ StartButton;
protected:
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->StartButton = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// StartButton
//
this->StartButton->Location = System::Drawing::Point(72, 64);
this->StartButton->Name = L"StartButton";
this->StartButton->Size = System::Drawing::Size(135, 87);
this->StartButton->TabIndex = 0;
this->StartButton->Text = L"button1";
this->StartButton->UseVisualStyleBackColor = true;
this->StartButton->Click += gcnew System::EventHandler(this, &Test::StartButton_Click);
//
// Test
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->StartButton);
this->Name = L"Test";
this->Text = L"Test";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void StartButton_Click(System::Object^ sender, System::EventArgs^ e) {
INPUT Input;
Input.type = INPUT_KEYBOARD;
Input.ki.wVk = 'A';
Input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
SendInput(true, &Input, sizeof(Input));
Input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(true, &Input, sizeof(Input));
}
};
}
|
Last edited by gogodr on Wed Dec 22, 2010 10:06 pm; edited 1 time in total |
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed Dec 22, 2010 4:00 pm Post subject: |
|
|
http://msdn.microsoft.com/en-us/library/ms173266%28v=vs.80%29.aspx
You have managed code inside DllMain
| Code: | bool WINAPI DllMain ( HMODULE hModule, DWORD dwReason, LPVOID lpvReserved )
{
switch ( dwReason ) {
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
if ( CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MyThread, NULL, 0, NULL) == NULL ) {
return FALSE;
}
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
} |
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Wed Dec 22, 2010 6:21 pm Post subject: |
|
|
"To resolve issues here, the code block that defines DllMain should be modified with #pragma unmanaged. The same should be done for every function that DllMain calls. "
Should I use #pragma unmanaged instead of #pragma once at the beggining of my test.h ?
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Wed Dec 22, 2010 6:48 pm Post subject: |
|
|
ok
I think I understood it. please let me know if I'm right ... (thanks for the help )
I should use
| Code: | | #pragma managed(push, off) |
before my DLLMain and Mythread
in order to make them unmanaged so they can compiled?
___
edit:
that made it work Thanks for the help.
Now I'm having troubles initializing my form since I dont know why it doesn't want to recognize my namespaces
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Thu Dec 23, 2010 12:03 pm Post subject: |
|
|
Compile test.h as a dll, then in your project import it like any other Resource.
ex
using test;
From there you should be able to call your namespace.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Thu Dec 23, 2010 12:21 pm Post subject: |
|
|
I'll try it...
but.. how do you do that?
here is the project file if anyone wants to take a better look at it and help D:
http://www.mediafire.com/?0qdkdldbkl692z0
|
|
| Back to top |
|
 |
iPromise Grandmaster Cheater
Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Thu Dec 23, 2010 1:24 pm Post subject: |
|
|
Project
->
... Properties
->
Linker
->
Additional Dependencies
->
Inherit from parent or project defaults
hope that fixed it, i experienced this problem before when I first start coding in C++.
|
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Thu Dec 23, 2010 1:37 pm Post subject: |
|
|
I can't find Inherit from parent or project defaults
this is what I have
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Tue Dec 28, 2010 12:06 pm Post subject: |
|
|
If you are still having issues, I will take a look tonight when I get home. Been off work for nearly 5 days now and I'm up to my eyes in it.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
|