zOpen() API returns null?

Posted By: hanw

zOpen() API returns null? - 06/01/21 06:52

Hi,

I am experimenting with the zInit, zData and zOpen APIs to control a zorro process.

I was able to build the zorroControl example by creating a console application in visual studio 2019 and added the source from Zorro/Source/ZorroControl to the project.

However, when running the application, the application returns "Can't initialize zorro processes"), which means this following code is failing to run.

Code
	if(!zOpen(2,"Control -run -h")) {	
		printf("Can't initialize Zorro process!"); return EXIT_FAILURE;
	}


My question is, is there an example on how to use the zOpen() API, what might be the problem?

Thanks
Posted By: jcl

Re: zOpen() API returns null? - 06/01/21 08:07

Reasons for returning 0 can be an error in the command line, a missing Zorro S license, a missing Zorro.exe, or a failed zInit call.
Posted By: hanw

Re: zOpen() API returns null? - 06/01/21 08:38

Thanks for the reply.

I have a Zorro S license. I am able to compile and run the Process.c program from NotePad++, I can get the zOpen api to work in C program when editing and running in Zorro GUI, but not a C++ program when editing and running from visual studio.
.
I think the zInit call is running fine, otherwise, the application would print a different error message.

Code
	if(!zInit(2,sizeof(int))) {
		printf("Can't initialize communication!"); return EXIT_FAILURE;
	}


The problem happens when I tried to build the ZorroControl cpp program. Here is the code I used. The program prints "handle=00000000"

The zInit, zData and zClose API seems to work fine. but zOpen returns 0 in the C++ program.

Code
#include "stdafx.h"
#include "ZorroControl.h"

int _tmain(int argc, _TCHAR* argv[])
{
// open ZorroControl.dll and get its function pointers
	HINSTANCE H = LoadLibrary(TEXT("ZorroControl.dll"));
	if(!H) {
		printf("Can't mount ZorroControl.dll!"); return EXIT_FAILURE;
	}
	_zInit zInit = (_zInit)GetProcAddress(H,"zInit");
	_zOpen zOpen = (_zOpen)GetProcAddress(H,"zOpen");
	_zClose zClose = (_zClose)GetProcAddress(H,"zClose");
	_zStatus zStatus = (_zStatus)GetProcAddress(H,"zStatus");
	_zData zData = (_zData)GetProcAddress(H,"zData");

// initialize process communication
	if(!zInit(2,sizeof(int))) {
		printf("Can't initialize communication!"); return EXIT_FAILURE;
	}

// get and clear the data area
	int* Info = (int*)zData(1);
	*Info = 0; 

	HANDLE open = zOpen(2, "-w 320");
	printf("handle=%p\n", open);

	// display it and quit
	printf("Zorro returned %i\n",*Info);

	zClose(2);

	Sleep(1000);
	return EXIT_SUCCESS;
}



Perhaps I'm missing something trivial. Is it related to how I loaded the ZorroControl.dll in C++ program? That seems to be the only difference between the Process.C and ZorroControl.




Attached picture zorrocontrol.PNG
Posted By: hanw

Re: zOpen() API returns null? - 06/01/21 10:53

Problem solved. I need to make sure ZorroControl.exe can find zorro.exe by copying zorro.exe to the save directory that ZorroControl.exe is executed along with several other dlls.
© 2024 lite-C Forums