[aspectc-user] (no subject)

Daniel Lohmann daniel.lohmann at informatik.uni-erlangen.de
Thu Mar 12 11:00:37 CET 2009


On 12.03.2009, at 08:12, Matthias.Ritter at metop.de wrote:

>
> Unfortunatly it still doesn't work.
> Of course my first try was with "WINAPI", that changes nothing.
> I reduced my code on a minimum and it looks like that:
>
> The Main-function:
>
> int main( void )
> {
>         Sleep( 1000 );
>         cout << "in main function" << endl;
>         getchar();
>         return 0;
> }
>
> my aspect:
>
> aspect foo
> {
>                 HANDLE myThread;
>                 int ThreadArgs;
>                 int myThreadId;
>                 pointcut Main() = execution("% main(...)");
>
>                 DWORD WINAPI bar(void* param)
>                 {
>                         cout << "in Thread-Function" << endl;
>                         return 0;
>                 }
>
>                 advice Main() : before()
>                 {
>                         cout << "aspect before main" << endl;
>                         myThread = CreateThread( NULL, 0, bar,  
> (void*)&ThreadArgs, 0, (LPDWORD)&myThreadId );
>                 }
>
>                 advice  Main() : after()
>                 {
>                         cout << "aspect after Main" << endl;
>                         TerminateThread (myThread, 0);
>                         CloseHandle(myThread);
>                 }
> };
>
> I tried the 3 lines "CreateThread", "TerminateThread" and  
> "CloseHandle" in an own main without weaving an aspect, and it works.
> Without the "CreateThread" call the aspect works fine.


Your bar() function seems to be a member of the aspect. Non-static  
member functions (aspects behave like classes in this respect) cannot  
be used directly as C-style callbacks, as expected by CreateThread()  
for the thread function. You can work around this by turning bar()  
into a static member function:

	static DWORD WINAPI bar(void* param);

Note that all this signature-errors and type-compatibility-issues are  
not so much related to AspectC++ but to C++ in general. You might want  
to try your code with a plain class first. Just make your aspect a  
class and every advice a member function of the class and see if that  
compiles.

Daniel 
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20090312/e6fc3776/attachment.html>


More information about the aspectc-user mailing list