You at least need to initialise fActionParamValueRef
result = sAIActionManager->AINewActionParamValue(&fActionParamValueRef);
You should also check the return values from the calls.
I tried with this, started getting new error saying "The file "file.ai" is in an unknown format and cannot be opened."
ASErr result = NULL;
AIActionParamValueRef fActionParamValueRef = NULL;
result = sAIActionManager->AIActionSetStringUS(fActionParamValueRef, kAIOpenDocumentNameKey, ai::UnicodeString(templatesDir.toStdString()));
result = sAIActionManager->AIActionSetInteger(fActionParamValueRef, kAIOpenDocumentColorModelKey, kDocCMYKColor);
result = sAIActionManager->PlayActionEvent(kAIOpenDocumentAction, kDialogOff, fActionParamValueRef);
Are you passing in the full path to the file or just the file name?
I'm passing full path
And if you open the file using file open in Illustrator it opens OK?
Are your result values all kNoErr (0)?
Yes. It opens if I open from illustrator. The return code of PlayActionEvent is not zero. It is 1398034256. I'm not sure where to check this error.
It seems there's some other problem. I'm able to open the file by hardcoding the path. Thank you for your time. It solved the problem.