cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

The 2025 Technology Preview Program is now live. Join today!

Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Bizarre GSErrCode -2130312313 returned by ACAPI

sxs
Booster

Hi everyone:

     *MyPlugin

               |--------------A.dll(third party dll)

               |--------------B.dll(third party dll)

 

     *MyPlugin_Entrance-----real add-on,including CheckEnvironment\RegisterInterface\Initialize\FreeData

 

1,Above is my project structure. 

2,Part of the code in MyPlugin is as follows:

  

extern "C" _declspec(dllexport)
void	Export()
{
	API_ProjectInfo project_info;
	auto err = ACAPI_ProjectOperation_Project(&project_info);
	
	err = NoError;
	void* origSight;
	err = ACAPI_Sight_SelectSight(nullptr, &origSight);
	
	return ;
}

3,Part of the code in MyPlugin_Entrance is as follows:

API_AddonType CheckEnvironment (API_EnvirParams* envir)
{
	RSGetIndString (&envir->addOnInfo.name, ID_ADDON_INFO, 1, ACAPI_GetOwnResModule ());
	RSGetIndString (&envir->addOnInfo.description, ID_ADDON_INFO, 2, ACAPI_GetOwnResModule ());

	return APIAddon_Preload;
}		// CheckEnvironment

//
typedef void (*PluginEntry)();
//
PluginEntry Do_Export = NULL;
//
static void LoadAssembly()
{
	std::string assembly_dir = GetExecutablDir();
	if (assembly_dir.empty())
		return;
	//
	std::vector<std::string> assemblys = { "A.dll", 									 
                                               "B.dll",										 
                                               "MyPlugin.apx"};

	for (size_t i = 0; i < assemblys.size(); i++)
	{
		auto assembly = assembly_dir + "/" + assemblys[i];
		//
		auto model = LoadLibrary(assembly.c_str());
		//get entry from plugin
		if (i == assemblys.size() - 1)
			Do_Export = (PluginEntry)GetProcAddress(model, "Export");
	}
}


GSErrCode ViewNotificationHandlerProc(const API_NotifyViewEventType* viewEvent)
{
	if (Do_Export)
	{
		Do_Export();
		return NoError;
	}

	return NoError;
}


GSErrCode Initialize	(void)
{
	//
	LoadAssembly();
	
	if (err == NoError)
		err = ACAPI_Notification_CatchViewEvent(APINotifyView_Opened, API_PublicViewMap, ViewNotificationHandlerProc);
	
	return NoError;
}		// Initialize


   

 The question is that ACAPI_ProjectOperation_Project and ACAPI_Sight_SelectSight return -2130312313 in function Export().

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Oleg
Expert

I dont know the errors reason. I didnt tried this infrastructure exactly as this.
And it very depend on how A.dll, B.dll work.

Personally, I would have done it differently. All API specific code in real API Addon only.

If you can directly use functionality A.dll, B.dll by GetProcAddress, MyPlugin will not needed.
If the MyPlugin.dll more convenient or needed, It will be like a high level "bridge" between the addon and a third-party dlls functionality and possible memory handling issues. The MyPlugin will not depends on API and not will linked to API. 

PS: It's not necessarily good or right, it's just my personal opinion.

View solution in original post

3 REPLIES 3
sxs
Booster

The code outside of ACAPI in the function Export() can execute normally.

Solution
Oleg
Expert

I dont know the errors reason. I didnt tried this infrastructure exactly as this.
And it very depend on how A.dll, B.dll work.

Personally, I would have done it differently. All API specific code in real API Addon only.

If you can directly use functionality A.dll, B.dll by GetProcAddress, MyPlugin will not needed.
If the MyPlugin.dll more convenient or needed, It will be like a high level "bridge" between the addon and a third-party dlls functionality and possible memory handling issues. The MyPlugin will not depends on API and not will linked to API. 

PS: It's not necessarily good or right, it's just my personal opinion.

sxs
Booster

Okay, thank you. You gave me some inspiration, I'll give it a try