Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hi folks,
I have a Problem with my J-Link Tool. I load in my J-Link Tool a Pro/Toolkit DLL. With following command:
...
Dll loadedDll = session.LoadProToolkitDll("MP_DLL", dllPath+dllName, dllPath, true);
Object retobj = loadedDll.ExecuteFunction(fktName, inputs);
retObj.GetOutputArguments();
...
Everything works fine for 10 till 12 steps and then I've get this Error:
Invalid wide string: failed to convert to multibyte
The failure seems to occure in the ExecuteFunction line.
After this Error my Java UI is closed and I get a return value of -1. But I can't catch these failure. I don't know what I should do ... had anyone an idea ?
First I think it would be a time problem, but there seem to be no time problem (I've build in timeouts with 1 second) no more or less parts would be processed.
I've tested it in Creo 2.0 and Creo Elements 5.0 on 64bit. Other commands works like a charme.
Best regards,
Eike
Hi Patrick, Hi Mark,
thanks for your answers so far. My actual Toolkit Code is this. I've looked at the inserting strings from the java side of evil 🙂
INPUTS : 0 : MDL_NAME : d7603_a_233_279_nbr<din7603_a_nbr>
INPUTS : 1 : MDL_TYPE : .prt
INPUTS : 0 : MDL_NAME : d7603_a_243_289_nbr<din7603_a_nbr>
INPUTS : 1 : MDL_TYPE : .prt
The first works the second don't work, but thats not everytime the same that doesn't work, so I think I've got a C Problem in my DLL somewhere.
basic.c
extern "C" PRO_TK_DLL_EXPORT ProError regenSolidMdl (ProArgument* inputs, ProArgument** outputs)
{
ProError ret = PRO_TK_NO_ERROR;
ProName mdlName = L";
ProName mdlType = L";
ProMdl mdl = NULL;
ProArgument argRelationMdlName;
ProValueData dataMdl;
ProArgument** o;
// add the output argument for model name and number of lines
ret = ProArrayAlloc (0, sizeof (ProArgument), 1, (ProArray*)outputs);
if (ret != PRO_TK_NO_ERROR)
return ret;
dataMdl.type = PRO_VALUE_TYPE_WSTRING;
swprintf(argRelationMdlName.label, L"MDL_NAME");
ret = ProArrayObjectAdd( (ProArray*)outputs, -1, 1, &argRelationMdlName );
// reads the input
ret = ProArgumentByLabelGet(inputs, L"MDL_NAME", &dataMdl);
if (ret == PRO_TK_NO_ERROR && (dataMdl.type == PRO_VALUE_TYPE_WSTRING))
{
wcscpy(mdlName, dataMdl.v.w);
}
ret = ProArgumentByLabelGet(inputs, L"MDL_TYPE", &dataMdl);
if (ret == PRO_TK_NO_ERROR && (dataMdl.type == PRO_VALUE_TYPE_WSTRING))
{
wcscpy(mdlType, dataMdl.v.w);
}
// read the model
if (wcslen(mdlName) > 0) {
ProMdlType type = GetMdlType(mdlType);
ret = ProMdlInit(mdlName, type, &mdl);
if (ret != PRO_TK_NO_ERROR)
return PRO_TK_CONTINUE;
}
// run function
ret = ProSolidRegenerate((ProSolid)mdl, PRO_REGEN_NO_FLAGS);
ProValuedataWstringSet(&dataMdl,mdlName);
((*outputs)[0]).value = dataMdl;
return ret;
}
FileUtil.c
/*
* GetMdlType returns the type of model according to the name
* mdlName: name of model
* return: error code
*/
ProMdlType GetMdlType(ProName mdlName) {
ProMdlType type;
wchar_t *ending = mdlName + (wcslen(mdlName)-4);
if (_wcsicmp(ending, L".PRT")==0)
{
type = PRO_MDL_PART;
}
else if (_wcsicmp(ending, L".ASM")==0)
{
type = PRO_MDL_ASSEMBLY;
}
else if (_wcsicmp(ending, L".DRW")==0)
{
type = PRO_MDL_DRAWING;
}
return type;
}
The Problem is that I can't get breakpoints in the DLL because it is loaded from outside. But I think to write a second DLL that loads it from the Toolkit side to load the functions from there.
Best regards,
and thank you in advance,
Eike
You're my hero's!
I've changed the order of the commands and change also the variables and don't reuse them. Now it seems like everything works alright.
I've added also the TEST_CALL_REPORT Functions. Here is my new version of the function that works alright.
extern "C" PRO_TK_DLL_EXPORT ProError regenSolidMdl (ProArgument* inputs, ProArgument** outputs) {
ProError ret = PRO_TK_NO_ERROR;
ProName mdlName = L";
ProName mdlType = L";
ProMdl mdl = NULL;
ProArgument argRelationMdlName;
ProValueData nameMdl;
ProValueData typeMdl;
ProValueData retMdl;
ProArgument** o;
if (ret != PRO_TK_NO_ERROR) return ret;
nameMdl.type = PRO_VALUE_TYPE_WSTRING;
// reads the input
ret = ProArgumentByLabelGet(inputs, L"MDL_NAME", &nameMdl);
TEST_CALL_REPORT ("ProArrayAlloc()", "ProArgumentByLabelGet()", ret, ret!=PRO_TK_NO_ERROR);
if (ret == PRO_TK_NO_ERROR && (nameMdl.type == PRO_VALUE_TYPE_WSTRING))
{
wcscpy(mdlName, nameMdl.v.w);
}
ret = ProArgumentByLabelGet(inputs, L"MDL_TYPE", &typeMdl);
TEST_CALL_REPORT ("ProArrayAlloc()", "ProArgumentByLabelGet()", ret, ret!=PRO_TK_NO_ERROR);
if (ret == PRO_TK_NO_ERROR && (typeMdl.type == PRO_VALUE_TYPE_WSTRING))
{
wcscpy(mdlType, typeMdl.v.w);
}
// read the model
if (wcslen(mdlName) > 0) {
ProMdlType type = GetMdlType(mdlType);
ret = ProMdlInit(mdlName, type, &mdl);
TEST_CALL_REPORT ("ProArrayAlloc()", "ProMdlInit()", ret, ret!=PRO_TK_NO_ERROR);
if (ret != PRO_TK_NO_ERROR)
return PRO_TK_CONTINUE;
}
// run function
if (mdl != NULL) {
ret = ProSolidRegenerate((ProSolid)mdl, PRO_REGEN_NO_FLAGS);
TEST_CALL_REPORT ("ProArrayAlloc()", "ProSolidRegenerate()", ret, ret!=PRO_TK_NO_ERROR);
}
// add the output argument for model name and number of lines
ret = ProArrayAlloc (0, sizeof (ProArgument), 1, (ProArray*)outputs);
TEST_CALL_REPORT ("ProArrayAlloc()", "regenSolidMdl()", ret, ret!=PRO_TK_NO_ERROR);
swprintf(argRelationMdlName.label, L"MDL_NAME");
ret = ProArrayObjectAdd((ProArray*)outputs, -1, 1, &argRelationMdlName );
TEST_CALL_REPORT ("ProArrayAlloc()", "ProArrayObjectAdd()", ret, ret!=PRO_TK_NO_ERROR);
ProValuedataWstringSet(&retMdl,mdlName);
((*outputs)[0]).value = retMdl;
return ret;
}
Best regards,
and many thanks,
Eike