Here is a trick -- rather than passing the device name in a variable attach it to the printer using a dummy mnemonic. When you open the printer, get the device name using winprt_setup read X$, then assign that value to a dummy mnemonic such as 'DV'.
Something like this:
->open (1) "*winprt*
->winprt_setup read x$
->mnemonic (1) 'DV'=x$
->print mnm('DV',1)
HPCDFA5D (HP Officejet 5740 series) on WSD-c8640f5c-7a68-4457-bbad-87b958a2cfa8.003d
Now when you want the device name simply access the DV mnemonic for the specified channel.