[PW - C#] How to get Datasource DisplayName Value?

How to get Datasource DisplayName Value? I'm found only

aaApi_GetDatasourceName

function...

Please, help me.

Parents Reply Children
  • You're welcome!

    For future reference, here's a code snippet to demonstrate how to get the datasource information including the Display Name:


    {
     AFX_MANAGE_STATE(AfxGetStaticModuleState());

        BOOL    bODBC = FALSE;
        LONG    lNativeType = 0;
        LONG    lLoginType = 0;
        WCHAR   strDSServerColonDSName[AADMS_BUFSIZE_DSNAME] = {'\0'};
        WCHAR   strUser[AADMS_BUFSIZE_USERNAME] = {'\0'};

        HDSOURCE hDataSource = aaApi_GetActiveDatasource();
        if (hDataSource==NULL)
        {
            // error...
            return -1;
        }
       
        // if we just want the general info, try this function
        if (!aaApi_GetConnectionInfo2(hDataSource, &bODBC, &lNativeType, 
            &lLoginType, strDSServerColonDSName, AADMS_BUFSIZE_DSNAME,
            strUser, AADMS_BUFSIZE_USERNAME, NULL, 0))
        {
            // error...
            return -1;
        }

        // to get more information, select the DS into a databuffer
        // and inspect it
        HAADMSBUFFER hDSDataBuffer = aaApi_SelectDataSourceDataBufferByHandle(hDataSource);
        if (hDSDataBuffer==NULL)
        {
            // error...
            return -1;
        }

        CString DSDisplayName;          // The DS Display Name
        CString DSJustTheName;          // The DS Name
        CString DSServerColonDSName;    // The full name - Server:DSName
       
        DSDisplayName       = aaApi_DmsDataBufferGetStringProperty
                                (hDSDataBuffer, DS_PROP_NAME, 0);
        DSJustTheName       = aaApi_DmsDataBufferGetStringProperty
                                (hDSDataBuffer, DS_PROP_INTERNALNAME, 0);
        DSServerColonDSName = aaApi_DmsDataBufferGetStringProperty
                                (hDSDataBuffer, DS_PROP_FULLNAME , 0);

        aaApi_DmsDataBufferFree(hDSDataBuffer);

        return 0;
    }

    HTHs

  • Dan,

    When using C#, how do you work with HAADMSBUFFER?
    Like .. in the next line... How do you make HAADMSBUFFER available in c#?
    HAADMSBUFFER hDSDataBuffer = aaApi_SelectDataSourceDataBufferByHandle(hDataSource);

    Thx.

    Kevin.
  • KBZA, in using C#, you use an IntPtr data type for the HAADMSBUFFER. Keep in mind this is a pointer, not the actual buffer so there is no memory for you to manange locally. You do need to use aaApi_DmsDataBufferFree (hDSDataBuffer) to free any buffers you create including the one created by the function Dan is recomending to use.


    Example:
    [DllImport(@"C:\Program Files\Bentley\ProjectWise\bin\dmscli.dll", EntryPoint = "aaApi_GetActiveDatasource", CharSet= CharSet.Unicode)]
    public static extern IntPtr aaApi_GetActiveDatasource();

    //declare and initalize the IntPtr

    IntPtr hDatasource = IntPtr.Zero;


    //this function performs a login, storing the hDatasource for Logout later.
    public static bool LogIn(string dsName)
    {
    string adminName = "???";
    string pw = "some_password";

    aaApi_Initialize(1/*AAMODULE_EXPLORER*/);
    if (false == aaApi_Login(0, dsName.ToString(), adminName, pw, "")) { return (false); }
    if (IntPtr.Zero == (hDatasource= aaApi_GetActiveDatasource())) { return (false); }
    return (true);
    }