Sign in to follow this  
Followers 0
Shane0000

Create a TCHAR in autoit.

19 posts in this topic

#1 ·  Posted (edited)

Im trying to use ObjectArx (Autocad) to set some data.

Problem is plain text is not recognized. Further reading shows that I need to pass a TCHAR [wchar_t] (unicode format).

WOuld I do this using:

DllCall ( "dll", "return type", "function" [, type1, param1 [, type n, param n]] )

Maybe DllCall(???,'wstr','text to be converted')

Edited by Shane0000

Share this post


Link to post
Share on other sites



TCHAR is actually the platform string. In modern Windows, it becomes wchar_t. In older Windows, it is char.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks, but what goes in the ??? area? what DLL do I need to call to simply create a wchar_t that I can later pass to AutoCad

DllCall(???,'wstr','text to be converted')

If thats the wrong approach I also found 'DllStructCreate("WCHAR")' but I wouldnt know how to then get text inside that pointer

thanks for the help, Im a complete noob when it comes to c++ type stuff

Also how would i convert from wchar back to plain text

Edited by Shane0000

Share this post


Link to post
Share on other sites

You actually need to create a DllStruct with a wchar array and set it to a certain size. Then you also typically pass the size of the parameter to the function using the string. You would then pass a pointer to the DllStruct.

Share this post


Link to post
Share on other sites

Below is as far as I got.

I think I did your step 1, step 2 & 3 make no sense to me, could I trouble you for an example.

Thanks

Local Const $iSize0 = StringLen('Key') + 1
Local Const $iSize1 = StringLen('value') + 1
Local Const $tTemp3 = DllStructCreate("wchar[" & $iSize0 & "]") ;your step 1 i believe
Local Const $tTemp4 = DllStructCreate("wchar[" & $iSize1 & "]")
DllStructSetData($tTemp3, 1, "Key")
DllStructSetData($tTemp4, 1, "Value")
msgbox(0,"test",DllStructGetData ($tTemp4, 1))

Share this post


Link to post
Share on other sites

You've got the right idea reading and writing to the variable. You'll have to show me the C(++) version of the function before I can really elaborate on the rest of it.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Below in lower code area is the details of the method I am trying to use. Calls to other methods return fine so Im sure the only thing can be properly defining the variables.

MY current call to the method:

Local Const $iSize0 = StringLen('Key') + 1
Local Const $iSize1 = StringLen('value') + 1
Local Const $tTemp3 = DllStructCreate("wchar[" & $iSize0 & "]")
Local Const $tTemp4 = DllStructCreate("wchar[" & $iSize1 & "]")
DllStructSetData($tTemp3, 1, "Key")
DllStructSetData($tTemp4, 1, "Value")
;my call to this method
$oAcadActDoc.SummaryInfo.addCustomSummaryInfo($tTemp3,$tTemp4)

If i could figure out 1 i can modify the example and fix the rest of my program.

Most of what I can find on AChar says that it is equivalent to TChar.

Most of the conversion from plain text to a unicode text done in VB is simply converting the text to TChar and this acceptable for the ACHAR (for autocad)

[ex. acutPrintf (_T("nNew Entity not Write")) ]

where '_T()' converts the text to an AutoCad friendly version.

Also this example: where ACHAR is assigned a TCHAR through _T()

ACHAR* szName = _T("MyTest");

Thanks for the help

AcDbDatabaseSummaryInfo::addCustomSummaryInfo
Collapse AllC++
virtual Acad::ErrorStatus addCustomSummaryInfo(
const ACHAR* key,
const ACHAR* value
) = 0;
Parameters
Parameters Description
const ACHAR* key Input key or name of the custom field to add to the list of custom fields
const ACHAR* value Input value or contents of the custom field
Description
This method should add a new custom field at the end of the existing list of custom fields.
Returns Acad::eOk if successful.
Edited by Shane0000

Share this post


Link to post
Share on other sites

Wait. Are you using ActiveX or DllCall because the two aren't intermixable.

Share this post


Link to post
Share on other sites

Im using active x, but I have to have a Tchar Var to get and send some types of data to the target app (AutoCad)

other methods return successfully

$oAcad = ObjGet("","AutoCAD.Application")
$oAcadActDoc = $oAcad.activedocument                  ;returns correctly, able to query this object even
$oAcadActDoc.SummaryInfo.NumCustomInfo          ;returns correctly

$oAcadActDoc.SummaryInfo.addCustomSummaryInfo($tTemp3,$tTemp4) ;does not work, Target app expects Tchar Vars

Share this post


Link to post
Share on other sites

You have no control over what type your variables are when using COM in AutoIt. AutoIt will format your variables to match the target function.

When you say it fails, what do you mean? What are the contents of the error reported?

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Not sure what this error is telling me,

$oAcadActDoc.SummaryInfo.addCustomSummaryInfo($tTemp3,$tTemp4)

And thats where I get the COM error 80020006, description 'UNKNOW NAME.'.

Ive checked that the method name is correct so I feel like its the variables.

Ive looked it (the error code 80020006) up in google and havent found much excluding Visual Fox Pro, says this error happens when ActiveX’s property or method name is mis-typed. And I think thats refering to the fact that variable types dont match when trying to interact with the method. But I dont know if that error is relevant to this error im getting.

This is the full text from the com error handler:

err.description is:

err.windescription is: 80020006

err.lastdllerror is: 0

err.scriptline is: 15

err.source is:

err.helpfile is:

err.helpcontext is: 13071088
Edited by Shane0000

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

And about AutoIt auto formatting the var types,

There is a another similar method where I provide it an integer and it returns 2 pieces of text 'tKey' & 'tValue'.

getCustomSummaryInfo($i,$tKey,$tValue)

If autoit auto formats the vars, id think that this method would work as the target app would be suppling the data, I just need to give the target app valid containers to put the data in, which autoit should have done. This method gives the same 80020006 error also

Edited by Shane0000

Share this post


Link to post
Share on other sites

Last I checked, reference parameters weren't supported in AutoIt COM, so the "two return values" wouldn't work period. That may have been changed some time ago though.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Ahh that would explain it i guess.

I ve got a 3k line app i did that worked fine until autocads move to T and A chars ....

I guess Ill have to do a multi language work around between Autoit and LiSP, but there's still no good way to transfer data between the 2 ....

Bummer, thanks for all the info and help

Edited by Shane0000

Share this post


Link to post
Share on other sites

TCHAR is platform dependent. A is ANSI which is single byte char. I think you mean A and W, in which case, there are usually two versions of a function. One ending in A and one ending in W. Try adding a W to the end of the function name. Granted it's not a COM convention, that's the last thing I can think of.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

This Achar is app specific to AutoCad and is assigned a Tchar (ACHAR* szName = _T("MyTest") )

All the ObjectArx -> AutoCad examples I find all pass Tchars.

From what Ive come across through google recently was that (my understanding) that Char is ansi, t/w/aChar are unicode (Not sure of what unicode even is for that matter).

And this is all new to me so I have no idea what the differences are between t w and a.

I think Im going to actually break down and take some programming classes. Perhaps I'll be able to revisit this latter in VB or C++

Anywho, have a good weekend!

Edited by Shane0000

Share this post


Link to post
Share on other sites

T isn't a specific character. It is a macro for whatever platform you target. W is a "wide character" because originally it was two bytes instead of just one. Unicode is one to four bytes per character depending on what's going on.

Interlingual text is probably one of the more difficult programming mechanisms.

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0