Jump to content
  • Advertisement
Sign in to follow this  
blueshogun96

QueueUserAPC, how is it (properly) utilized?

This topic is 2542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Lately, I've been curious as to how QueueUserAPC works and how could it be used in a game? I read the MSDN documentation and I didn't quite grasp what it was saying about the function and other articles I found were a bit too confusing IMO. So, I did what I normally do when trying to learn something that doesn't make much sense to me: play around with it until I can see what makes it useful. Yeah, sometimes I have to learn the "Naruto" way before somethings finally click. Also, I'm a bit tired and learning a new API during a late night while barely awake isn't exactly easy for me.

This probably isn't very useful to games, I assume. So far, the only game I've seen that actually uses it was Metal Slug 3 (Xbox), but that's a long story.

I wrote a basic program to test it. It works fine, but I still don't quite see any way to utilize it.



#define _WIN32_WINNT 0x0500

#include <windows.h>
#include <stdio.h>


DWORD __stdcall thread_function( void* Param )
{
int i = 0;

while( i++ < 10 )
printf( "Thread...\n" );

return 0;
}

void __stdcall apc_function( DWORD dwParam )
{
int i = 0;

while( i++ < 60 )
printf( "APC...\n" );
}

int main( int argc, char** argv )
{
HANDLE hThread = NULL;

hThread = CreateThread( NULL, 0, thread_function, NULL, 0, NULL );

if( !hThread )
printf( "Could not create thread!\n" );

if( !QueueUserAPC( apc_function, hThread, 0 ) )
printf( "Could not create APC!\n" );

WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );

return 0;
}


So what it does is it calls the APC function first, then calls the thread function. Maybe I'm not using it right.

Please forgive my stupidity, my curiosity gets overwhelming sometimes.

Shogun.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!