|
Well, just wild guess and I tried it just today at morning, but under some limitations you can go (probably) this way:
If you can stick with the C call convention (no pascal, at least I think), and you can specify fixed type for return parameter, you can define the function signature as follows:
typedef DWORD (__stdcall *pFunction)(...);
Then you can call it in this way:
int execute()
{
MyruntimeFunc = (pFunction)GetProcAddress( NULL,"TestFunction");
MyruntimeFunc( 1 );
return -1;
}
extern "C"
{
__declspec( dllexport ) DWORD TestFunction( DWORD ard )
{
int x = 0;
return 0;
};
}
Because TestFunction knows what to look for on the stack, she'll find it. You only have to make you sure that you'll put the correct types (very important, (BYTE)1 is here not the same as (DWORD)1 ) in correct order.
It's just a morning idea, before I finally wake up, but maybe it will help you. I tested it inside one single .exe file, so maybe some of my assumptions are bad. But at least I tried
|
|
|
|
|
Hi,
is it possible, to start an executable file as a child process? And if not, how can i get an handle on the program I've started?
thanks, Michael
|
|
|
|
|
|
Can some please guide me to run an exe without clicking it & restarting the pc after modification in registry. Is there any way that it can be achieved ?
Regards,
Ibraheem
|
|
|
|
|
CreateProcess()
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
how will it load itself (without clicking or any user interaction) .... ???? can u plz briefly explain
Regards
|
|
|
|
|
It's you who needs to explain. When do you want it to run ? If you want it to run on reboot, follow Tom's advice. If you want your code to cause it to run, use CreateProcess or ShellExecute. If you want it to run every time your PC starts, put it in the Run registry key, or the startup folder.
If you want precise advice, ask precise questions.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Alrtie ... plz see my new post ... I hope u get a better idea now
Regards,
Ibraheem
|
|
|
|
|
Christian is right. It is a little bit hard to interpret your question so I tried to guess. CreateProcess will launch the exe from within your code. ShellExecute too (this is easier to use but not recommended by Microsoft). It is impossible (a telepath would prove me wrong) to start a program without telling the computer to do so. Tom and Ravi gave you excellent answers when it comes to the exe being executed at startup without any user interaction.
// Afterall, I realized that even my comment lines have bugs
Time is the fire in which we burn.
|
|
|
|
|
Toni78 wrote:
ShellExecute too (this is easier to use but not recommended by Microsoft).
Sorry, I meant to say WinExec, not ShellExecute.
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
|
Alrtie ... plz see my new post ... I hope u get a better idea now
Regards,
Ibraheem
|
|
|
|
|
Following on Tom's post, here's[^] a useful link that describes the Run and RunOnce registry keys.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Okay . I accept my mistake :P ... Well what i exactly want is say i have an executable . I know this executable can be runned by clicking it or any sort of user interaction ... or can be runned when the pc reboots ... but let say i want to run on a specific let say 10.00 am .... now other executable from outside runs that exe but this exes starts running by its own .... I hope i am little bit clear now .... Is it possible ??? and what exactly createprocess do ... can it help me in achieving this goal. i can explain it in more detail if any1 of u still dont reach to the point what I want .....
Thanx anyways
Regards,
Ibraheem
|
|
|
|
|
Use Task Scheduler to run the executable at the desired time. That is the simplest way.
|
|
|
|
|
Yea ... but again that would have been set by user interaction ... I want zero user interaction just like when window reboots a program can start running but I want more that is program starts of its own. That is, reboot of the window should not be needed. It starts executing of its own, even if the pc has not been restarted. Is it possible ?
Regards,
Ibraheem
|
|
|
|
|
All methods require some level of interaction. If there is no interaction how will the computer know what you want it to do?
Putting an entry in the registry at HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run will cause your application to run when a user logs on. This does require interaction but it is very minimal and only needs to be done once.
Also if there is no interaction at all how will you get your application onto the target machine?
|
|
|
|
|
Sounds like it's a virus....
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If I understand correctly what you are asking it is impossible.
No program can spontaneously start executing without some trigger.
If a program is not running it is not loaded into memory, it is
just a file on the disk. How can a disk file load itself into
memory and start running without an outside agent instructing it
to do so?
Steve T
|
|
|
|
|
Dear friends,
I am trying to convert 3 strings to BSTRs. But the method i am using is not working. It is giving me wrong results. Please tell me the reason why this is not wrking. Please see the code:
<br />
<br />
struct Student<br />
{<br />
BSTR firstName;<br />
<br />
BSTR lastName;<br />
<br />
BSTR fatherName;<br />
};<br />
<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
std::string firstName = "Bob";<br />
<br />
std::string lastName = "Andrew";<br />
<br />
std::string fatherName = "Jones";<br />
<br />
Student s;<br />
<br />
s.firstName = _bstr_t(firstName.c_str());<br />
<br />
s.lastName = _bstr_t(lastName.c_str());<br />
<br />
s.fatherName = _bstr_t(fatherName.c_str());<br />
<br />
std::wcout << s.firstName << std::endl;<br />
<br />
std::wcout << s.lastName << std::endl;<br />
<br />
std::wcout << s.fatherName << std::endl;<br />
<br />
return 0;<br />
}<br />
The program is giving me following result:
Bob.
Jones.
Jones.
Please tell me the reason that why the second and third conversions created trouble. While debugging we can see the that the first two conversions were successful. But during third conversion, the previous one automatically changed to reflect the third.
I am using _bstr_t OR CComBSTR in order to avoid explicit call to SysFreeString()/SysAllocString() . Both _bstr_t and CComBSTR are behaving in the manner i described above.
|
|
|
|
|
What's actually happening is that the third BSTR is being created to point to the same memory as the first, and therefore the first now points to memory that has been assigned the value of the third. It makes no difference what order you do it in, the third _bstr_t returns a BSTR that points to the same memory as the first one did. If I add a fourth BSTR field, it happens again. It still happens if I avoid std::string and use constant fields. Basically, the only way I could avoid it was to turn the fields in the struct to be _bstr_t's.
I used to use _bstr_t a lot to convert strings, and I've never seen it do this before.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It's happening because the temporary _bstr_t's get destroyed as soon as the assignment statement ends. The OP has raw BSTRs on the LHS of the assignment statement, so he essentially ends up with a dangling BSTR. When you have a _bstr_t or a CComBSTR on the LHS, the copy constructor (or the assignment operator) runs and makes a copy (using SysAllocString), so it runs fine.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Wow - that really sucks. As far as I can see, that's a bug in _bstr_t.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Not really. That's the only way _bstr_t can release memory held by it's internal member variable. If it didn't release it on destruction, then it becomes the responsibility of the user to call SysFreeString. Just
_bstr_t("Senthil");
will leak memory.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
The reason why this is happening is because you're not using _bstr_t correctly. When you say
s.firstName = _bstr_t(firstName.c_str());
what's happenings is, _bstr_t constructor gets called with firstname.c_str() as the argument. It does a SysAllocString and creates a BSTR internally (let's call it m_BSTR). Because you have the BSTR . on the LHS of the assignment statement, the conversion operator
operator BSTR()
{
return m_BSTR;
}
executes and you get a BSTR in s.firstName . What next happens is the reason why you're getting incorrect values. The destructor for _bstr_t runs (because it's lifetime ends after the assigment statement completes) and it does a SysFreeString on m_BSTR.
So what you have in s.firstName is essentially a dangling pointer, it's pointing to freed memory. You're just lucky that it didn't crash, it's reusing that freed memory and maybe that's why you're getting the same BSTR value.
The same case applies to CComBSTR also. The solution is simple, you just replace your plain BSTRs in the Student structure with a CComBSTR or _bstr_t . That way, the copy constructor (or the assignment operator) runs and does a SysAllocString for you, so you end up with a valid BSTR .
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|