Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Wrong clientdata pointer in callback function

Explorer ,
Apr 29, 2016 Apr 29, 2016

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 ?

TOPICS
Acrobat SDK and JavaScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 04, 2016 May 04, 2016

Consider, for example: the callback will need to know which AVDoc is just opened, which is not possible if the only parameter is clientData.

Translate
Community Expert ,
Apr 29, 2016 Apr 29, 2016

What do you use as aClientData ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 29, 2016 Apr 29, 2016

I made a class CclientData and I want to pass this through.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2016 Apr 29, 2016

Did you create an instance of this class?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 29, 2016 Apr 29, 2016

Yes ofcourse and I declared it static

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2016 Apr 29, 2016

Where did you declared it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 29, 2016 Apr 29, 2016

I suspect the days is already a pointer and you do not want the address of the pointer (double indirection)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 29, 2016 Apr 29, 2016

Sorry days -> data

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 03, 2016 May 03, 2016

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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 04, 2016 May 04, 2016

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 04, 2016 May 04, 2016

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 !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 04, 2016 May 04, 2016

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 04, 2016 May 04, 2016

That is this:

extern ACCB1 void ACCB2 myNotificationCallback(void *clientData);


And for the callback that works correctly:

extern ACCB1 void ACCB2 MyPluginCommand(void *clientData);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 04, 2016 May 04, 2016

I think we have the explanation. You have the wrong number of parameters. Each callback has different parameters and you must be correct.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 04, 2016 May 04, 2016

Could you please tell me where I miss some parameters ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 04, 2016 May 04, 2016

Please refer to the documentation or header files for the correct 3 parameters for an AVDocDidOpen callback.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 04, 2016 May 04, 2016

Consider, for example: the callback will need to know which AVDoc is just opened, which is not possible if the only parameter is clientData.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 04, 2016 May 04, 2016
LATEST

Thank you, it must be these 3 ones:

AVDoc myDoc, ASInt32 error, void *clientData

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines