Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++ MFC COM]BSTR e derivati

    ciao.
    Ho la seguente riga di codice da convertire dal vb 6 a vc++ 7.0 mfc:

    res=SapModel.FrameObj.AddByCoord(-300, 0, 0, -100, 0, 124, Name)
    in c++
    hr=pSapModel->FrameObj->AddByCoord(0, 0, 1, 0, 0, 10,B,L"R1",L"2",L"Global");

    dove il parametro Name in vb è una stringa e in c++ è un BSTR* e R1 2 e Global sono dei _bstr_t.
    cosa sono i BSTR?
    come faccio la conversione?
    in c++ continua ad avere un hresult hr = false.

    la documentazione della funzione è questa per vb:
    Syntax
    SapObject.SapModel.FrameObj.AddByCoord

    VB6 Procedure
    Function AddByCoord(ByVal xi As Double, ByVal yi As Double, ByVal zi As Double, ByVal xj As Double, ByVal yj As Double, ByVal zj As Double, ByRef Name As String, Optional ByVal PropName As String = "Default", Optional ByVal UserName As String = "", Optional ByVal CSys As String = "Global") As Long

    Parameters
    xi, yi, zi

    The coordinates of the I-End of the added frame object. The coordinates are in the coordinate system defined by the CSys item.

    xj, yj, zj

    The coordinates of the J-End of the added frame object. The coordinates are in the coordinate system defined by the CSys item.

    Name

    This is the name that the program ultimately assigns for the frame object. If no UserName is specified, the program assigns a default name to the frame object. If a UserName is specified and that name is not used for another frame, cable or tendon object, the UserName is assigned to the frame object, otherwise a default name is assigned to the frame object.

    PropName

    This is Default, None, or the name of a defined frame section property.

    If it is Default, the program assigns a default section property to the frame object. If it is None, no section property is assigned to the frame object. If it is the name of a defined frame section property, that property is assigned to the frame object.

    UserName

    This is an optional user specified name for the frame object. If a UserName is specified and that name is already used for another frame object, the program ignores the UserName.

    CSys

    The name of the coordinate system in which the frame object end point coordinates are defined.

    Remarks
    This function adds a new frame object whose end points are at the specified coordinates.

    The function returns zero if the frame object is successfully added, otherwise it returns a nonzero value.

    VBA Example
    Sub AddFrameObjByCoord()
    'dimension variables
    Dim SapObject As Sap2000.SapObject
    Dim SapModel As cSapModel
    Dim ret As Long
    Dim Name As String

    'create Sap2000 object
    Set SapObject = New SAP2000.SapObject

    'start Sap2000 application
    SapObject.ApplicationStart

    'create SapModel object
    Set SapModel = SapObject.SapModel

    'initialize model
    ret = SapModel.InitializeNewModel

    'create model from template
    ret = SapModel.File.New2DFrame(PortalFrame, 3, 124, 3, 200)

    'add frame object by coordinates
    ret = SapModel.FrameObj.AddByCoord(-300, 0, 0, -100, 0, 124, Name)

    'close Sap2000
    SapObject.ApplicationExit False
    Set SapModel = Nothing
    Set SapObject = Nothing
    End Sub

    Release Notes
    Initial release in version 11.00.

    See Also
    AddByPoint

    Grazie.

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381

    Re: [c++ MFC COM]BSTR e derivati

    Andiamo con ordine. Per lavorare con COM è obbligatorio usare unicode.
    cosa sono i BSTR?

    A BSTR, known as basic string or binary string, is a pointer to a wide character string used by Automation data manipulation functions.
    typedef OLECHAR FAR* BSTR;

    BSTRs are wide, double-byte (Unicode) strings on 32-bit Windows platforms and narrow, single-byte strings on the Apple® PowerMac™.
    Una stringa VB è una BSTR mascherata, quindi è sempre double byte.
    Lavorare direttamente in C++ con le BSTR è rognoso, occorre invocare funzioni apposite per la gestione. Per questo Microsoft ha creato una classe _bstr_t per la loro gestione. Si trova nell'header comutil.h insieme alla _variant_t che prima o poi userai.
    Usando quella classe, si può passare agevolmente da un char* o wchar* ( e qualcos'altro) ad una BSTR incapsulata e viceversa.

    Esempio:
    codice:
       if (cptr) {
    	BSTR b;
    	if (cptr->get_text(&b) != S_OK) return bstr_t(L"");
    	return bstr_t(b,false);
       }
    Per il resto, ti rimando a MSDN per approfondimenti.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    grazie.
    Ti posso chiedere ancora una cosa?
    La mia funzione com mi richiede un puntatore a bstr(BSTR*)
    ho provato cosi' :
    BSTR b =NULL;
    b=bstr_t("b");
    BSTR * b1=&b;
    è corretto?o ci sono degli altri problemi con questi tipi
    perchè questo codice continua a restituire(nella funzione addbycoord) false e non va:

    BSTR b =NULL;
    b=bstr_t("b");
    BSTR* b1=&b;
    hr = pSapModel->FrameObj->AddByCoord(0, 0, 1, 0, 0, 10,b1,L"R1",L"2",L"Global");

    non riesco a capire perchè

    Grazie.

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    il codice dell esempio in c# non lo capisco:

    string temp_string1;
    string temp_string2
    string[] FrameName;

    FrameName = new string[3];
    temp_string1 = FrameName[0];
    temp_string2 = FrameName[0];
    ret = SapModel.FrameObj.AddByCoord(0, 0, 0, 0, 0, 10, ref temp_string1, "R1", "1", "Global");
    FrameName[0] = temp_string1;
    ret = SapModel.FrameObj.AddByCoord(0, 0, 10, 8, 0, 16, ref temp_string1, "R1", "2", "Global");
    FrameName[1] = temp_string1;
    ret = SapModel.FrameObj.AddByCoord(-4, 0, 10, 0, 0, 10, ref temp_string1, "R1", "3", "Global");
    FrameName[2] = temp_string1;

    perchè fa tutti quei giri con framename e temp_string?

  5. #5
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,470
    Ma parliamo di C++ o C# ?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  6. #6
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    c++ , ma gli esempi che ho riportato sono in vb6 e c#

  7. #7
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,470
    Originariamente inviato da giuseppe500
    c++ , ma gli esempi che ho riportato sono in vb6 e c#
    Ritorniamo al C++ ... lascia perdere gli altri linguaggi, ti assicuro che si fa solo confusione ...

    Cosa devi fare con C++ e le BSTR?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  8. #8
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Non: BSTR* b1=&b; (assegni l'indirizzo della classe bstr_t), ma:

    BSTR b1 = b.copy();

    come doumentato qui:
    http://msdn.microsoft.com/en-us/library/zthfhkd6.aspx

    Curiosità. Ce l'hai l'header file C++ di questo ACTIVEX?

  9. #9
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    no ,non c'è l'ho l'header , l'ho incluso con #import e pensavo che fosse suficente.
    Non è sufficente?
    Adesso provo con copy.
    Grazie.

  10. #10
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Più che altro, con l'header non dovresti procedere a tentoni per conoscere i tipi da passare alle funzioni. Anche perché può darsi che qualche parametro debba essere passato come tipo VARIANT e sia mascherato da VB o C#.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.