VARIANT Datentyp????
-
Hi
Ich sitze gerade an einer Applikation, die ich mit MFC unter VS2005 schreibe. Diese soll "SocketWrench" verwenden, und ich konnte das COM Element auch soweit in meine Form hineinziehen und kann es auch ansprechen. ich habe dem Element, das ich in die Form gezogen habe eine Member-Variable gegeben und kann nun über diese Variable z.B. eingeben:
m_SocketWrench1.connect(); und hier ist auch schon mein Problem:
Das sagt die Hilfe:Connect Method Establish a connection with a remote server. Syntax object.Connect( [RemoteAddress], [RemotePort], [Protocol], [Timeout], [Options], [LocalAddress], [LocalPort] ) Remarks This method establishes a network connection with a remote server. All arguments are optional. If a given argument is missing, then a corresponding property or properties must be set before attempting the connection, as follows: RemoteAddress, which may be a hostname or IP address, defaults to the value of the HostAddress property if it is defined. Otherwise, it defaults to the value of the HostName property. RemotePort specifies the port number that the server is using to listen for connections. If this argument is not specified, the value of the RemotePort property will be used as the default. Protocol specifies the protocol that should be used when establishing the connection. If this argument is not specified, the value of the Protocol property will be used as the default. One of the following values may be used: Value Constant Description 6 swProtocolTcp Specifies the Transmission Control Protocol. This protocol provides a reliable, bi-directional byte stream. This is the default protocol. 17 swProtocolUdp Specifies the User Datagram Protocol. This protocol is message oriented, sending data in discrete packets. Note that UDP is unreliable in that there is no way for the sender to know that the receiver has actually received the datagram. Timeout specifies the amount of time until a blocking operation fails. A value of zero indicates that the control should wait indefinitely for the operation to complete. If this argument is not specified, the value of the Timeout property will be used as the default. Options specifies one or more socket options which are to be used when establishing the connection. The value is created by combining the options using a bitwise Or operator. Note that if this argument is specified, it will override any property values that are related to that option. Value Constant Description 1 swOptionBroadcast This option specifies that broadcasting should be enabled for datagrams. This option is invalid for stream sockets. 2 swOptionDontRoute This option specifies default routing should not be used. This option should not be specified unless absolutely necessary. 4 swOptionKeepAlive This option specifies that packets are to be sent to the remote system when no data is being exchanged to keep the connection active. This option is only valid for stream sockets. 8 swOptionReuseAddress This option specifies that the local address can be reused. This option is commonly used by server applications. 16 swOptionNoDelay This option disables the Nagle algorithm, which buffers unacknowledged data and insures that a full-size packet can be sent to the remote host. 32 swOptionInLine This option specifies that out-of-band data should be received inline with the standard data stream. This option is only valid for stream sockets. &H10000000 swOptionSecure This option specifies that a secure SSL connection is to be negotiated and established. LocalAddress specifies the local IP address of the network adapter that the control should use when establishing the connection. If this argument is not specified, the control will bind to any suitable adapter on the local system. Using a specific local address when establishing a TCP connection is not recommended. LocalPort specifies the local port number that the control should use when establishing the connection. If this argument is not specified, an appropriate local port number will be assigned for the connection. Using a specific local port number when establishing a TCP connection is not recommended. Return Value A value of zero is returned if the connection was successful. Otherwise, a non-zero error code is returned which indicates the cause of the failure. See Also HostAddress Property, HostName Property, RemotePort Property, RemoteService Property, Disconnect Method, Broadcast Property, Route Property, KeepAlive Property, ReuseAddress Property, NoDelay Property, InLine Property, Secure PropertyBefehl:
m_socketWrench1.Connect("www.google.de",80,6,10, NULL, NULL, NULL);Das Tutorial zu dem Modul sagt aber .Connect reicht mit 2 Parametern, den Rest nimmt es default-werte, aber bei mir sagt der Compiler sinngemäß ich muss 6 werte eingeben und die URL am Anfang kann er nicht in einen VARIANT Typen konvertieren.
Wie wandel ich das Char-Array in einen VARIANT um?!
Liebe Grüße
Basti
-
Vl. hilft dir das weiter:
TCHAR chTmp[MAX_PATH] = _T("http://www.google.at"); COleVariant varURL(chTmp);varURL müsstest du nun an deine Funktion übergeben können.
-
Ein String in einem Varient ist ein BSTR!
Das einfachste Du verwendest einfach: CComBSTR("meinurl")Default Werte darfsz Du nicht als NULL übergeben. Du musst die Notation von COM verwenden, in diesem Fal ein VARAINT vom Typ VT_ERROR mit scode==DISP_E_PARAMNOTFOUND!
-
ich habe es jetzt mal testweise so gemacht:
TCHAR chUrl[MAX_PATH] = _T("10.64.1.22"); TCHAR chPort[MAX_PATH] = _T("21"); TCHAR chProto[MAX_PATH] = _T("6"); TCHAR chTimeout[MAX_PATH] = _T("10"); TCHAR chOptions[MAX_PATH] = _T("0"); TCHAR chLocalAdress[MAX_PATH] = _T("0"); TCHAR chLocalPort[MAX_PATH] = _T("0"); ..... COleVariant varURL(chUrl); COleVariant varPORT(chPort); COleVariant varPROTO(chProto); COleVariant varTIMEOUT(chTimeout); COleVariant varOPTIONS(chOptions); COleVariant varLOCALADRESS(chLocalAdress); COleVariant varLOCALPORT(chLocalPort); m_SocketWrench2.Connect(varURL,varPORT,varPROTO,varTIMEOUT,varOPTIONS,varLOCALADRESS,varLOCALPORT); ......... void CWrenchServerDlg::OnConnectSocketwrench4() { MessageBox(_T("Wonderful"),_T("success"),MB_OK); }Kann ich da statt MAX_PATH einfach die Byte-Anzahl eingeben, die ich brauche um die Variable darin zu speichern, und muss ich das "\0" mitberechnen?
Danke für die Hilfe bisher

-
Du musst gar keine maximale Länge angeben. Die Daten werden sowieso intern kopiert.
Warum machst Du es nicht gleich so:m_SocketWrench2.Connect(COleVariant(_T("10.64.1.22")),COleVariant(_T("21")),COleVariant(_T("6")),...);
-
stimmt, hast recht

Habe nicht auf Anhieb verstanden was der Code macht, also dieses COleVariant
-
Es kapselt einen VARIANT und sorgt auch dafür, dass dessen interner Speicher freigegeben wird. Und es hat entsprechende typsichere Konstruktoren...
Ich bevorzuge CCoVariant, ist aber Geschmacksache.
-
Der Tipp mit dem VT_ERROR kam mir wie gerufen!
Es kapselt einen VARIANT ...
Ja das dachte ich bisher auch. Aber es muss trotzdem Unterschiede geben.
Verwende ich bei meiner WordAutomation die COleVariant funktioniert es nur mit den Original-Klassen aus der TypeLibrary. In meiner abgeleiteten Automations-Klasse bekomme ich die
COleException: scode = severity: SEVERITY_ERROR, facility: FACILITY_NULL ($C0000005).
Zu Deutsch "Keine Fehlermeldung verfügbar"
Nehme ich dort VARIANT geht alles. Aber es ist mir echt zu mühsam, für jeden der zig Parameter den entsprechenden VARIANT zu bilden.Weiß jemand, woran es liegen kann, dass VARIANT aber nicht COleVariant funktioniert?
-
Wahrscheinlich werden nicht die korrekten Typen gebildet und Du verwendest evtl. falsche KOnstruktoren.
Zeig mal Code wie Du die VARIANTs baust und wie Du das mit COleVariant machst.
BTW: Ich mag CComVariant lieber...
-
also ich habe mir die ganze Sache jetzt mal ein wenig betrachtet.
Habe nun folgenden Code und versuche so ein bisschen mit dem ActiveX Modul rumzuspielen und will das irgendwan mal verstehen *g*void CWrenchServerDlg::OnErrorSocketwrench4(const VARIANT& ErrorCode, const VARIANT& Description) { CComVariant Err_Code = ErrorCode; CComVariant Err_Descr = Description; CComBSTR* teststring; BstrFromVector(teststring, ErrorCode); MessageBox(_T("hier die description"),_T("hier der errorcode"),MB_OK); }Will im Prinzip aus dem Eventhandler Errorcode und Description ausgeben. Aber so ganz steig ich noch nicht durch. beim aktuellen Code kommt
Fehler 1 error C2664: 'BstrFromVector': Konvertierung des Parameters 1 von 'ATL::CComBSTR *' in 'SAFEARRAY *' nicht möglich c:\dokumente und einstellungen\basti\eigene dateien\visual studio 2005\projects\wrenchserver\wrenchserver\wrenchserverdlg.cpp 216
Und was ist ein "Event sink"? Und hat jmd. evtl. nen guten Link zu nem Text der sich mit COM Programmierung befasst, weil ich nicht UNBEDINGT auf die SocketWrench API zurückgreifen möchte.
Liebe Grüße und Danke für die Hilfe
Basti
-
Wahrscheinlich werden nicht die korrekten Typen gebildet und Du verwendest evtl. falsche Konstruktoren.
Komplizierte Datentypen habe ich (zumindes im Open) gar nicht drin.
Edit: ich nehm das mal hier raus. Hat ja nichts mit der Ursprungsfrage zu tun.
-
Dieser Code ist Irrsinn!
EigeneWordDocuments doc = wordApp->get_Documents()); doc.Open(LPCTSTR(docName));Wie kannst Du einen LPDISPTACH Zeiger als LPCTSTR casten?
Welchen Sinn soll das haben?Das umkopieren in einen neuen VARIANT ob nun CComVaiant oder COleVarient nützt nichts.
Du musst entsprechende dem Typ in dem Variant Deine nachricht anzeigen.
-
Wie kannst Du einen LPDISPTACH Zeiger als LPCTSTR casten?
Wieso? docName ist ein const char *
Du musst entsprechende dem Typ in dem Variant Deine nachricht anzeigen.
Wie meinst Du dass?
-
Hmm... mir erschliesst sich leider noch nicht genau wie mir das hilft, kann es vllt. genauer erläutern was geschehen muss und den Code erklären?
-
Sorry wegen docName! Habe ich irgendwie überlesen.
Aber warum castest Du dann bitte?
Meide casts, wenn ein cast nötig ist überlege 3mal warum!Hast Du Dir mal angesehen, was ein VARIANT ist?
Ein VARIANT ist variant, d.h. er kann ein INT enthalten einen BSTR, ein LONG ein BYTE, ein Array...Du musst also entsprechende des Typs im VARIANT reagieren, oder den Typ umwandeln in das was Du möchest VariantChangeType!
-
Sebastian, hast recht, dir hilft das sicher nicht weiter.
Mein Problem ist, man hat mir fertigen Uralt-Quellcode vorgesetzt, den ich nun anpassen und erweitern muss. Momentan kämpfe ich mit den OLE-Grundlagen und habe dies hier beim Suchen nach COleVariant gefunden.
-
Aber warum castest Du dann bitte
Ach frag mich nicht (s. letzten Beitrag).
Du musst also entsprechende des Typs im VARIANT reagieren
Ich dachte, das hätte ich, zumindest mit dem VARIANT (varFalse.boolVal=false; varFile.bstrVal=...). Aber COleVariant ist mir immer noch schleierhaft. Na vielleicht habe ich' s bis Montag kapiert.
Ich klinke mich jetzt lieber aus und "studiere" erst mal Microsoft.
-
hehe okay, aber was muss ich jetzt an meinem Code ändern dass ich die 2 Daten in einer Messagebox ausgeben kann?!

Gruß Basti
-
Ich habs! Danke Martin für den Denkanstoß.
COleVariant(docName)wars. Manchmal ist man doch besch...
-
sebastian87 schrieb:
hehe okay, aber was muss ich jetzt an meinem Code ändern dass ich die 2 Daten in einer Messagebox ausgeben kann?!

Gruß BastiWas bekommst Du denn übergeben?
Jetzt sag nicht VARIANTs... :xmas1:
-
Naja im Prinzip wird an den Eventhandler OnError die 2 Variants übergeben die den errorcode und die description enthalten. Wie ich mit den Daten nun weiter verfahren muss um die wichtigen informationen auszulesen weis ich leider nicht und dummerweise auch nicht wie die generiert werden. hab einfach nur auf dem Dialogfeld rechtsklick auf das OCX gemacht und dan eben Eventhandler hinzufügen...:
void CWrenchServerDlg::OnErrorSocketwrench4(const VARIANT& ErrorCode, const VARIANT& Description) { CComVariant Err_Code = ErrorCode; CComVariant Err_Descr = Description; CComBSTR* teststring; BstrFromVector(teststring, ErrorCode); MessageBox(_T("hier die description"),_T("hier der errorcode"),MB_OK); }