General information
Category:
Coding, syntax & commands
Paul,
Thank you for the info. I am picking up where David left off and am also a C++ novice trying to invoke the VFP COM object. David was able to resolve the initial compile error, however, I'm now getting the following errors when I try compile:
error C2660: 'm_set' : function does not take 3 parameters
error C2660: 'm_get' : function does not take 2 parameters
I am getting this error for every VFP method being invoked, even though m_get() has 3 parameters defined, etc. Any suggestions? I've looked at the Rick Strahl article and it isn't obvious what we're doing wrong. Here's the first part of VFP m_set:
Function m_set
Lparameters tcPropName,tuPropValue,tcType
Here is how it is being invoked from C++:
setValue (oServer, "dInvoice","12/21/2002");
static void setValue (IsqlarinvcPtr &oServer, const char *name, const char *value)
{
oServer->m_set (&_variant_t(_bstr_t(name)), &_variant_t(_bstr_t(value)), &_variant_t(OLESTR("C"))); //
printValue (oServer, name);
}
Complete C++ code follows for reference...
Thank you,
Rebecca
/ call_ar_com_object.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include
#import "d:\vamsql\rlp\vamole.tlb"
//int APIENTRY WinMain(HINSTANCE hInstance,
// HINSTANCE hPrevInstance,
// LPSTR lpCmdLine,
// int nCmdShow)
//{
// TODO: Place code here.
// return 0;
//}
/*
** C++ test program for COM object sqlArInvc
**
*/
// I'm guessing this is the right namespace.
// You can probably figure it out by looking at the wrapper classes
// created by the #import statement.
using namespace vamole;
/* It appears that m_set and m_get can handle various types of inputs. I'm not
sure what the deal is with this. I'm assuming the third arg is "C" for character,
"N" for numerice, and I don't know what "A" means.
*/
// Set a value which is a character string, and then query the COM object and print
// it to stdout, just to check.
static void setValue (IsqlarinvcPtr &oServer, const char *name, const char *value) ;
static char *getValue (IsqlarinvcPtr &oServer, const char *name) ;
static void printValue (IsqlarinvcPtr &oServer, const char *name) ;
static int getNumericValue (IsqlarinvcPtr &oServer, const char *name) ;
//int main (int argc, char **argv)
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
printf ("Starting test...\n");
_variant_t vResult;
// Pointer - I + lowercase class name + Ptr
IsqlarinvcPtr oServer;
// NOTE: calling the object - not the pointer!
oServer.CreateInstance("vamole.sqlArInvc");
//vResult = oServer->m_init ((&_variant_t(OLESTR("Buds"))));
vResult = oServer->m_init ( &_variant_t(OLESTR("Buds")), &_variant_t( OLESTR("d:\\VAMSQL\\rlp\\") ) );
printf ("m_init returned %d\n", bool (vResult));
setValue (oServer, "cCustNo", "ADRIAN");
setValue (oServer, "cInvNo", "k");
// ArInvc Constraints
// Following require 1 or 0:
// I'm assuming that these should all be passed as strings, but I'm not sure.
setValue (oServer, "lfrttax1", "1");
setValue (oServer, "lfrttax2", "1");
setValue (oServer, "lmultiso", "1");
setValue (oServer, "lprtcod", "1");
setValue (oServer, "lprtinvc", "1");
setValue (oServer, "lprtlbl", "1");
setValue (oServer, "lprtslip", "1");
setValue (oServer, "ltaxontax", "1");
setValue (oServer, "lusecusitm", "1");
setValue (oServer, "lvoid", "1");
// [Some ] Required Fields
setValue (oServer, "caracc","012345678901234567890123456789"); // Acct Recv GL
setValue (oServer, "cbAddr1", "Pebble Road");
setValue (oServer, "cBankNo","0123456789"); // Lookup
setValue (oServer, "cBCity","Newark");
setValue (oServer, "cBCompany","The Company");
setValue (oServer, "cBContact","David S.");
setValue (oServer, "cBPhone","908-111-2222");
setValue (oServer, "cBState","NJ");
setValue (oServer, "cBZip","11111");
setValue (oServer, "cEnterBy","DS");
setValue (oServer, "cPayCode","0123456789");
setValue (oServer, "cType","1");
setValue (oServer, "cWarehouse","MAIN");
setValue (oServer, "dCreate", "12/21/2002");
setValue (oServer, "dInvoice","12/21/2002");
oServer->m_add ();
int errCount = getNumericValue (oServer, "errCount");
//int i ;
//for (i = 1; i < errCount; i++)
// {
// char buf[500];
// sprintf (buf, "errs(%d,2)", i ) ;
// This is probably wrong - I don't know what type "A" means
//printValue (oServer, buf);
//}
printf ("Test completed\n");
return 0;
}
static void setValue (IsqlarinvcPtr &oServer, const char *name, const char *value)
{
// oServer->m_set ((&_variant_t(OLESTR(name))), (&_variant_t(OLESTR(value))), (&_variant_t(OLESTR("C"))));
oServer->m_set (&_variant_t(_bstr_t(name)), &_variant_t(_bstr_t(value)), &_variant_t(OLESTR("C"))); //
printValue (oServer, name);
}
// Get a string value from the COM object
static char *getValue (IsqlarinvcPtr &oServer, const char *name)
{
// _variant_t vResult = oServer->m_get (&_variant_t(OLESTR(name)), (&_variant_t(OLESTR("C"))));
_variant_t vResult = oServer->m_get (&_variant_t(_bstr_t(name)), &_variant_t(OLESTR("C")));
return _bstr_t(vResult);
}
// Get a numeric value from the COM object.
static int getNumericValue (IsqlarinvcPtr &oServer, const char *name)
{
//_variant_t vResult = oServer->m_get (&_variant_t(OLESTR(name)), (&_variant_t(OLESTR("C"))));
_variant_t vResult = oServer->m_get (&_variant_t(_bstr_t(name)), &_variant_t(OLESTR("C"))); //
// I'm not sure if this is the right field of vResult to use.
return vResult.lVal;
}
// Get a value from the COM object and print it to stdout.
static void printValue (IsqlarinvcPtr &oServer, const char *name)
{
printf ("m_get (%s) = %s\n", name, getValue (oServer, name));
}
/******************************************************************/
/**************************[END OF tstole.cpp]*************************/
/******************************************************************/
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only