Copy link to clipboard
Copied
Hello,
I am trying to pass a data object to a callback function when a document loads.
This is my code:
AVAppRegisterNotification(AVDocDidOpenNSEL, gExtensionID, ASCallbackCreateNotification(AVDocDidOpen, (void*)myNotificationCallback), (void*)&aClientData);
The callback function is as follows:
ACCB1 void ACCB2 myNotificationCallback(void *clientData)
{
....
}
However my clientData pointer address in the callback function is not the same as the address when I put it in the AVAppRegisterNotification function.
How is this possible ?
Consider, for example: the callback will need to know which AVDoc is just opened, which is not possible if the only parameter is clientData.
Copy link to clipboard
Copied
What do you use as aClientData ?
Copy link to clipboard
Copied
I made a class CclientData and I want to pass this through.
Copy link to clipboard
Copied
Did you create an instance of this class?
Copy link to clipboard
Copied
Yes ofcourse and I declared it static
Copy link to clipboard
Copied
Where did you declared it?
Copy link to clipboard
Copied
I suspect the days is already a pointer and you do not want the address of the pointer (double indirection)
Copy link to clipboard
Copied
Sorry days -> data
Copy link to clipboard
Copied
I declared Ccliendata in my init.cpp as static
static CclientData aClientData;
And in the function
ACCB1 ASBool ACCB2 PluginMenuItem(char* MyMenuItemTitle, char* MyMenuItemName, CclientData & aClientData)
{
AVMenubar menubar = AVAppGetMenubar();
AVMenu volatile commonMenu = NULL;
if (!menubar)
return false;
DURING
// Create our menuitem
menuItem = AVMenuItemNew (MyMenuItemTitle, MyMenuItemName, NULL, true, NO_SHORTCUT, 0, NULL, gExtensionID);
AVMenuItemSetExecuteProc (menuItem, ASCallbackCreateProto(AVExecuteProc, MyPluginCommand), (void*) &aClientData);
AVAppRegisterNotification(AVDocDidOpenNSEL, gExtensionID, ASCallbackCreateNotification(AVDocDidOpen, (void*)myNotificationCallback), (void*)&aClientData);
...
return true;
}
For the callback function AVMenuItemSetExecuteProc (menuItem, ASCallbackCreateProto(AVExecuteProc, MyPluginCommand), (void*) &aClientData);
aClienData is valid !!!
But NOT for AVAppRegisterNotification(AVDocDidOpenNSEL, gExtensionID, ASCallbackCreateNotification(AVDocDidOpen, (void*)myNotificationCallback), (void*)&aClientData);
Copy link to clipboard
Copied
Did you try my suggestion? If so, what happened? Or did you not understand my reply? Or is it not applicable (it may be wrong, as I am a C not a C++ programmer; if you were using a static C structure I would be sure).
Copy link to clipboard
Copied
I did not understand your reply I think. Fact is aClientData is not a pointer, so I need to use &aClientData and use that as parameter. (and cast it to void*)
Funny thing is that for the other callback function, I use the same parameter, and that will work !
Copy link to clipboard
Copied
I understand your reasoning; it is probably correct. So, please post the function declaration for myNotificationCallback (the actual contents are not important, just the declaration).
Copy link to clipboard
Copied
That is this:
extern ACCB1 void ACCB2 myNotificationCallback(void *clientData);
And for the callback that works correctly:
extern ACCB1 void ACCB2 MyPluginCommand(void *clientData);
Copy link to clipboard
Copied
I think we have the explanation. You have the wrong number of parameters. Each callback has different parameters and you must be correct.
Copy link to clipboard
Copied
Could you please tell me where I miss some parameters ?
Copy link to clipboard
Copied
Please refer to the documentation or header files for the correct 3 parameters for an AVDocDidOpen callback.
Copy link to clipboard
Copied
Consider, for example: the callback will need to know which AVDoc is just opened, which is not possible if the only parameter is clientData.
Copy link to clipboard
Copied
Thank you, it must be these 3 ones:
AVDoc myDoc, ASInt32 error, void *clientData
Find more inspiration, events, and resources on the new Adobe Community
Explore Now