Re: EuCom - Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Jonas Temple wrote:
> 
> 
> Here's my code thus far:

include cwbx.ew
with trace
without warning

integer cwb_cmd, as400_system, errors
atom void, sys_ptr, ptr, err_count

com_err_out(1)
trace(1)

cwb_cmd = create_com_object( Command_clsid_ix )
as400_system = create_com_object( AS400System_clsid_ix )

sys_ptr = allocate_string(ansi_to_unicode("DILBERT.MKG.COM"))
void = invoke(as400_system,
{AS400System_m_Define},{sys_ptr},{VT_BSTR},DISPATCH_METHOD)
void = invoke(cwb_cmd, {Command_p_system,DISPID_PROPERTYPUT},{as400_system},
	{VT_UNKNOWN},DISPATCH_PROPERTYPUT)

ptr = allocate_string(ansi_to_unicode("SNDMSG MSG('This is a test')
TOUSR(JOTEMPL)"))
void = invoke(cwb_cmd, {Command_m_Run},{ptr},{VT_BSTR},DISPATCH_METHOD)
errors = ref_com_object(Errors_clsid_ix, invoke(cwb_cmd, {Command_p_Errors}, {},
{},
	DISPATCH_PROPERTYGET))

err_count = invoke(errors, {Errors_p_Count}, {}, {}, DISPATCH_PROPERTYGET)

free(sys_ptr)
free(ptr)
release_com()


First thing I notice is that you're not using the bstr routines.  These
actually let COM allocate the memory, which is important because they're
reference counted.  Other objects might be using the pointers, so a simple
free() could cause problems later.  Make sure you use alloc_bstr() and
free_bstr().  They're documented under "Utilities" in eucom.htm.

> 
> What this program is attempting to do is connect to an AS400 and execute
> a command to send me a message.
> 
> The problem I'm having is with the as400_system object.  I set the system
> name correctly but the problem comes up when I try to set the 
> as400_system object in the cwb_cmd object.  I get a "Member not found" 
> error message.  I also tried you suggestion of DISPATCH_PROPERTYPUTREF
> and I got a machine exception.
> 
> Here's the sample VB code from the documentation:
> 
> ' Declare variables
> Dim systemNames As New cwbx.systemNames
> Dim as400 As New cwbx.AS400System
> Dim cmd As New cwbx.Command
> ' Retrieve the default system and use it to initialize the AS400System
> ' object
> as400.Define systemNames.DefaultSystem
> ' Set the System property of the command object
> Set cmd.System = as400

The "Set " here indicates that you need to use DISPATCH_PROPERTYPUTBYREF
(according to my FAQ that I just reread :).

> In the cwbx.ew that tbrowse created the property comments for the
> Command_p_system has a type of IcwbxSystem instead of the usual VT_xxxx
> value.  Don't know if that has anything to do with it.  I could send you
> the cwbx.ew file, if that would help.

IcwbcSystem is a COM interface for your cwbx object.  This should be
VT_UNKNOWN.  VT_UNKNOWN really means IUnknown, which is the most basic
interface, and which is included in all interfaces.  Try this:

void = invoke(cwb_cmd, {Command_p_system,DISPID_VALUE},
	{get_obj_this(as400_system)},{VT_UNKNOWN},DISPATCH_PROPERTYPUTBYREF)


You might be able to get rid of the DISPID_VALUE (some objects require
you to always pass named arguments, and some don't care).  The 
get_obj_this() is important, because as400_system is a EuCOM index 
(think Win32Lib control ids), but you need to pass the actual pointer.

Good luck,
Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu