Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Help with a little code please?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Dec 22, 2010 11:51 am    Post subject: [C++] Help with a little code please? Reply with quote

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
View user's profile Send private message MSN Messenger
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed Dec 22, 2010 4:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Dec 22, 2010 6:21 pm    Post subject: Reply with quote

"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
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Dec 22, 2010 6:38 pm    Post subject: Reply with quote

http://msdn.microsoft.com/en-us/library/0adb9zxe%28VS.80%29.aspx

Read up on how the pragma is used.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Wed Dec 22, 2010 6:48 pm    Post subject: Reply with quote

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 Very Happy 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
View user's profile Send private message MSN Messenger
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu Dec 23, 2010 12:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Thu Dec 23, 2010 12:21 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Thu Dec 23, 2010 1:24 pm    Post subject: Reply with quote

Project

->

... Properties

->

Linker

->

Additional Dependencies

->

Inherit from parent or project defaults

Smile hope that fixed it, i experienced this problem before when I first start coding in C++.
Back to top
View user's profile Send private message MSN Messenger
gogodr
I post too much
Reputation: 125

Joined: 19 Dec 2006
Posts: 2041

PostPosted: Thu Dec 23, 2010 1:37 pm    Post subject: Reply with quote

I can't find Inherit from parent or project defaults
this is what I have

Back to top
View user's profile Send private message MSN Messenger
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Tue Dec 28, 2010 12:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites