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 


[Help] Passing Pointer to Array as Argument

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Sat Jul 12, 2008 4:29 pm    Post subject: [Help] Passing Pointer to Array as Argument Reply with quote

I'm trying to make a DLL injector. I want to inject multiple DLLs, so I pass an array of strings to my inject function. The problem is how do I do that? I want to pass them by reference, not by value. Here's the code.

Code:

void __stdcall InjectDllEx(LPCSTR lpszProcessName, LPCSTR* lpDllArray, int nNumberOfElements)
{
   int nIndex;
   DWORD dwProcessId = 0xFFFFFFFF;
   HANDLE hProcess = INVALID_HANDLE_VALUE;

   while(TRUE)
   {
      if (GetProcessIdByName(lpszProcessName, &dwProcessId, 0xFFFFFFFF)) //Found first process
      {
         if (GetProcessIdByName(lpszProcessName, &dwProcessId, dwProcessId)) //Found second process
         {
            hProcess = OpenProcess(dwProcessInjectDll, FALSE, dwProcessId);
            if (hProcess != INVALID_HANDLE_VALUE)
            {
               for (nIndex = 0; nIndex < nNumberOfElements; nIndex++)
               {
                  InjectDll(hProcess, (lpDllArray)[nIndex]);
               }
               break;
            }
         }
      }      
   }

   return;   
}
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Jul 12, 2008 4:39 pm    Post subject: Reply with quote

Code:
LPCSTR array[] = { "String1, "String2, "String3" };
InjectDllEx("notepad.exe", array, 3);
Back to top
View user's profile Send private message
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Sat Jul 12, 2008 5:00 pm    Post subject: Reply with quote

And C++ will pass "array" variable as a pointer?
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Sat Jul 12, 2008 5:19 pm    Post subject: Reply with quote

You can also call InjectDll in a loop:
Code:
for (int i = 0; i < 3; ++i)
InjectDll("notepad.exe", array[i]);
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Jul 12, 2008 6:03 pm    Post subject: Reply with quote

rapion124 wrote:
And C++ will pass "array" variable as a pointer?


The variable that denotes the array is a pointer to the first element in the array, not the value of the first element in the array.

Basically: array == &array;

So yes, you will be passing a pointer to the array.
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