Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Ne moze se prebaciti CString u BSTR ???

[es] :: C/C++ programiranje :: Ne moze se prebaciti CString u BSTR ???

[ Pregleda: 2254 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Burgos
Nemanja Borić
Amazon Web Services
Berlin

Član broj: 12484
Poruke: 1947
195.252.80.*

Sajt: stackoverflow.com/users/1..


+480 Profil

icon Ne moze se prebaciti CString u BSTR ???06.04.2005. u 16:47 - pre 231 meseci
Nece nikako da se prebaci. Samo prvi znak uspe...

Code:
#include <afxwin.h>
#include <oleauto.h>

#include "Winsock2.h"        // This header file has been added in addition to the wizard 
                            // generated code.


extern "C" __declspec(dllexport)
 BSTR Enumerate() 
{
    CString strTemp;
//    CListBox *pList = (CListBox*) GetDlgItem(IDC_LIST1);


    struct hostent *host;    
    struct in_addr *ptr;    // To retrieve the IP Address

     DWORD dwScope = RESOURCE_CONTEXT;
    NETRESOURCE *NetResource = NULL;    
    HANDLE hEnum;    
    WNetOpenEnum( dwScope, NULL, NULL, NULL, &hEnum );    
    
    WSADATA wsaData;  
    WSAStartup(MAKEWORD(1,1),&wsaData);

    if ( hEnum )    
    {
        DWORD Count = 0xFFFFFFFF;
        DWORD BufferSize = 2048;
        LPVOID Buffer = new char[2048];
        WNetEnumResource( hEnum, &Count, Buffer, &BufferSize );

        NetResource = (NETRESOURCE*)Buffer;

        char szHostName[200];

        for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++ )
        {    
            if ( NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY )
            {
                if ( NetResource->lpRemoteName )
                {
                    CString strFullName = NetResource->lpRemoteName;
                    
                    if ( 0 == strFullName.Left(2).Compare("\\\\") )
                        strFullName = strFullName.Right(strFullName.GetLength()-2);

                    gethostname( szHostName, strlen( szHostName ) );
                    host = gethostbyname(strFullName);
                    ptr = (struct in_addr *) host->h_addr_list[0];

                    int a = ptr->S_un.S_un_b.s_b1;  // Eg. 211.40.35.76 split up like this.
                    int b = ptr->S_un.S_un_b.s_b2;  //     40
                    int c = ptr->S_un.S_un_b.s_b3;  //     35
                    int d = ptr->S_un.S_un_b.s_b4;  //     76

                    strTemp.Format("%s -->  %d.%d.%d.%d",strFullName,a,b,c,d);
                    strTemp+="|?*?|";
                    MessageBox(NULL,strTemp,NULL,NULL);
                }
            }
        }
        delete Buffer;
        WNetCloseEnum( hEnum );
    }
    WSACleanup();    
    BSTR Return = strTemp.AllocSysString;
    MessageBox(NULL,(LPCSTR)Return,NULL,NULL);
    return SysAllocString((BSTR) Return);
}



Potrebne biblioteke: Mpr.lib ws2_32.lib
 
Odgovor na temu

Burgos
Nemanja Borić
Amazon Web Services
Berlin

Član broj: 12484
Poruke: 1947
195.252.80.*

Sajt: stackoverflow.com/users/1..


+480 Profil

icon Re: Ne moze se prebaciti CString u BSTR ???06.04.2005. u 17:00 - pre 231 meseci
Code:
BSTR Result = tmpString.GetBuffer(50);
         tmpString.ReleaseBuffer();
 
Odgovor na temu

janjam

Član broj: 34603
Poruke: 69
212.200.96.*



+16 Profil

icon Re: Ne moze se prebaciti CString u BSTR ???07.04.2005. u 13:24 - pre 231 meseci
Ovde kod tebe nije problem u prebacivanju CString-a u BSTR. To se je odradjeno korektno. Problem je u tome sto si u MessageBox-u uradio cast BSTR u LPCSTR , a to vec ne ide tako. Ako zelis da imas BSTR vec ga imas, ali ako hoces da ga vidis u MessageBox-u moras da ga konvertujes. Probaj:

cast u CString
Code:

    
BSTR Return = strTemp.AllocSysString;
MessageBox(NULL, (CString)Return, NULL, NULL);



ili preko cast-a u _bstr_t
Code:


BSTR Return = strTemp.AllocSysString;
MessageBox(NULL, (_bstr_t)Return, NULL, NULL);



[Ovu poruku je menjao janjam dana 07.04.2005. u 14:42 GMT+1]
 
Odgovor na temu

Burgos
Nemanja Borić
Amazon Web Services
Berlin

Član broj: 12484
Poruke: 1947
195.252.80.*

Sajt: stackoverflow.com/users/1..


+480 Profil

icon Re: Ne moze se prebaciti CString u BSTR ???07.04.2005. u 13:41 - pre 231 meseci
Hvala
 
Odgovor na temu

[es] :: C/C++ programiranje :: Ne moze se prebaciti CString u BSTR ???

[ Pregleda: 2254 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.