Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8769273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:17:55+00:00 2026-06-13T17:17:55+00:00

i had an global structure like this:- struct MachineList { BSTR AccountId; BSTR MachineId;

  • 0

i had an global structure like this:-

struct MachineList
    {
    BSTR AccountId;
    BSTR MachineId;
    BSTR Make;
    char* Make1;
    BSTR Model;
    char* Model1;
    BSTR SerialNumber;
    BSTR IpAddress1;
    char* IpAddress;
    BSTR Port1;
    int Port;
    BSTR LocationCode;
    SOCKET Sock;
    BSTR Status;
} MACHINELIST,*PMACHINELIST;
int MachineCount=-1;

I had an XML which i parse and store it in structure like this:-
i want to add every structure that is filled by parsing into the stl list so i added the following code

vector<struct  MACHINELIST > SS;

Now i get the following error :-

error C2371: ‘MACHINELIST’ : redefinition; different basic types error
C2512: ‘MACHINELIST’ : no appropriate default constructor available

int GetMachineList(char *Xmlpath)
{
    wLog->WriteDebugLog("Inside GetMachineList\n");
    try 
    {
        //Qualify namespase explicitly to avoid Compiler Error C2872 "ambiguous symbol" during linking.
        //Now Msxml2.dll use the "MSXML2" namespace
        //(see http://support.microsoft.com/default.aspx?scid=kb;en-us;316317):
        MSXML2::IXMLDOMDocumentPtr docPtr;//pointer to DOMDocument object
        MSXML2::IXMLDOMNodeListPtr NodeListPtr;//indexed access. and iteration through the collection of nodes
        MSXML2::IXMLDOMNodePtr DOMNodePtr;//pointer to the node

        MSXML2::IXMLDOMNode *pIDOMNode = NULL;//pointer to element's node
        MSXML2::IXMLDOMNode *pIParentNode = NULL;//pointer to parent node
        MSXML2::IXMLDOMNode *pIAttrNode = NULL;//pointer to attribute node
        MSXML2::IXMLDOMNamedNodeMapPtr DOMNamedNodeMapPtr;//iteration through the collection of attribute nodes
        MSXML2::IXMLDOMNodeList *childList=NULL;//node list containing the child nodes


        //Variable with the name of node to find: 
        BSTR strFindText  = L" ";//" " means to output every node

        //Variables to store item's name, parent, text and node type:
        BSTR bstrItemText,bstrItemNode, bstrItemParent,bstrNodeType;

        //Variables to store attribute's name,type and text:     
        BSTR bstrAttrName, bstrAttrType, bstrAttrText;

        HRESULT hResult;

        int i = 0;//loop-index variable
        int n = 0;//lines counter


        //Initialize COM Library:
        CoInitialize(NULL);

        //Create an instance of the DOMDocument object:
        docPtr.CreateInstance(__uuidof(DOMDocument30));

        // Load a document:
        _variant_t varXml(Xmlpath);//XML file to load//uncomment this
        _variant_t varResult((bool)TRUE);//result 

        varResult = docPtr->load(varXml);

        if ((bool)varResult == FALSE)
        {
            wLog->WriteErrorLog("failed to load XML file. Check the file name\n");
            printf("failed to load XML file. Check the file name\n");

            return 1;
        }

        //Collect all or selected nodes by tag name:
        NodeListPtr = docPtr->getElementsByTagName(strFindText);//original
        // NodeListPtr=   docPtr->documentElement->getElementsByTagName(strFindText) ;



        //Output the number of nodes:
        //printf("Number of nodes: %d\n", (NodeListPtr->length));

        //Output root node:
        docPtr->documentElement->get_nodeName(&bstrItemText);
        //%ls formatting is for wchar_t* parameter's type (%s for char* type):
        printf("\nRoot: %ls\n", bstrItemText);  



**PMACHINELIST MachineList;**



        for(i = 0; i < (NodeListPtr->length); i++)
        {

            if (pIDOMNode) pIDOMNode->Release();            
            NodeListPtr->get_item(i, &pIDOMNode);


            if(pIDOMNode )
            {               

                pIDOMNode->get_nodeTypeString(&bstrNodeType);

                //We process only elements (nodes of "element" type): 
                BSTR temp = L"element";

                if (lstrcmp((LPCTSTR)bstrNodeType, (LPCTSTR)temp)==0) 
                {
                    n++;//element node's number
                    printf("\n\n%d\n", n);//element node's number
                    printf("Type: %ls\n", bstrNodeType);

                    pIDOMNode->get_nodeName(&bstrItemNode);
                    if(0== wcscmp(bstrItemNode, L"ModuleSettings"))
                    {
                        isModuleSettings=TRUE;
                        //MS.account_id_name
                        printf("");
                    }


                    printf("Node: %ls\n", bstrItemNode);                
                    if(0== wcscmp(bstrItemNode, L"Machine"))
                    {
if(MachineCount++!=-1)
                        {
                            SS.push_back(MachineList);
                        }
                        //printf("value of count is %d\n",count);
                        count++;
                        //printf("value of count is %d\n",count);

                        isMachineList=TRUE;

                        **MachineList=new MACHINELIST;
                        MachineCount++;**
                        //MS.account_id_name

                    }
                    if(0== wcscmp(bstrItemNode, L"/Machine"))
                    {
                        printf("detected");
                    }
                    pIDOMNode->get_text(&bstrItemText);
                    printf("Text: %ls\n", bstrItemText);
                    if(isModuleSettings)//work here
                    {
                        if(0== wcscmp(bstrItemNode, L"capture_local_dir"))
                        {
                            CapturelocalDir=bstrItemText;
                            printf("CapturelocalDir is %ls\n",CapturelocalDir);
                        }
                        if(0== wcscmp(bstrItemNode, L"capture_log_dir"))
                        {
                            CapturelogDir=bstrItemText;
                            printf("CapturelogDir is %ls\n",CapturelogDir);
                        }
                        if(0== wcscmp(bstrItemNode, L"capture_log_level"))
                        {
                            CapturelogLevel=bstrItemText;
                            printf("CapturelogLevel is %ls\n",CapturelogLevel);
                        }
                        if(0== wcscmp(bstrItemNode, L"capture_request_interval"))
                        {
                            CapturerequestInterval=bstrItemText;
                            printf("CapturerequestInterval is %ls\n",CapturerequestInterval);
                        }
                        if(0== wcscmp(bstrItemNode, L"capture_connection_interval"))
                        {
                            CaptureConnectionInterval=bstrItemText;
                            printf("CaptureConnectionInterval is %ls\n",CaptureConnectionInterval);
                        }
                    }
                    if(isMachineList)
                    {
                    /*  PMACHINELIST MachineList;
                        MachineList=new MACHINELIST;*/


                        if(0== wcscmp(bstrItemNode, L"MachineId"))
                        {
                            m_LocalStorage.machinelist[count].MachineId=bstrItemText;
                            //MachineList.MachineId=bstrItemText;
                            MachineList->MachineId=bstrItemText;
                            //printf("Machine id is %ls\n",ML[count].MachineId);
                        }
                        if(0== wcscmp(bstrItemNode, L"IpAddress"))
                        {
                            m_LocalStorage.machinelist[count].IpAddress=bstrItemText;
                            m_LocalStorage.machinelist[count].IpAddress1=_com_util::ConvertBSTRToString(bstrItemText);
                            printf("ip address1 is %s\n",m_LocalStorage.machinelist[count].IpAddress1);
                            MachineList->IpAddress=_com_util::ConvertBSTRToString(bstrItemText);
                            //printf("Machine id is %ls\n",ML[count].MachineId);
                        }
                        if(0== wcscmp(bstrItemNode, L"Port"))
                        {
                            m_LocalStorage.machinelist[count].Port=bstrItemText;
                            m_LocalStorage.machinelist[count].Port1=_wtoi(bstrItemText);
                            MachineList->Port==_wtoi(bstrItemText);
                            //printf("Machine id is %ls\n",ML[count].MachineId);
                            printf("port1 is %d\n",m_LocalStorage.machinelist[count].Port1);
                        }
                        if(0== wcscmp(bstrItemNode, L"Model"))
                        {
                            m_LocalStorage.machinelist[count].Model=bstrItemText;
                            m_LocalStorage.machinelist[count].Model1=_com_util::ConvertBSTRToString(bstrItemText);
                            MachineList->Model1=_com_util::ConvertBSTRToString(bstrItemText);
                            //printf("Machine id is %ls\n",ML[count].MachineId);
                        }
                        if(0== wcscmp(bstrItemNode, L"Make"))
                        {
                            m_LocalStorage.machinelist[count].Make=bstrItemText;
                            m_LocalStorage.machinelist[count].Make1=_com_util::ConvertBSTRToString(bstrItemText);
                            MachineList->Make1=_com_util::ConvertBSTRToString(bstrItemText);
                            //printf("Machine id is %ls\n",ML[count].MachineId);
                        }
                        if(0== wcscmp(bstrItemNode, L"SerialNumber"))
                        {
                            m_LocalStorage.machinelist[count].SerialNumber=bstrItemText;
                            MachineList->SerialNumber=bstrItemText;
                            //printf("Machine id is %ls\n",ML[count].MachineId);
                        }
                        if(0== wcscmp(bstrItemNode, L"AccountId"))
                        {
                            m_LocalStorage.machinelist[count].AccountId=bstrItemText;
                            MachineList->AccountId=bstrItemText;
                            //printf("Machine id is %ls\n",ML[count].MachineId);
                        }
                        if(0== wcscmp(bstrItemNode, L"location_code"))
                        {
                            m_LocalStorage.machinelist[count].LocationCode=bstrItemText;
                            MachineList->LocationCode=bstrItemText;
                            //printf("Machine id is %ls\n",ML[count].MachineId);
                        }
                    }




                    //Get the attributes:
                    int j = 0;//loop-index variable
                    long length;// number of attributes in the collection

                    DOMNamedNodeMapPtr = pIDOMNode->attributes;

                    hResult = DOMNamedNodeMapPtr->get_length(&length);


                }
            }
        }

        //Do not forget to release interfaces:
        pIDOMNode->Release();
        pIDOMNode = NULL;
        //pIParentNode->Release();
        pIParentNode = NULL;


    } 

    catch(...)
    {
        wLog->WriteErrorLog("Exception occurred while parsing XML\n");

    }


    CoUninitialize();
        printf("value of machine count is %d",MachineCount);
    wLog->WriteDebugLog("Ends GetMachineList\n");
    return 0;


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:17:57+00:00Added an answer on June 13, 2026 at 5:17 pm

    To declare a vector of any type, you need to pass the type as a template parameter. In your case, the type is MachineList:

    vector<MachineList> SS;
    

    To add an instance, you can use for example push_back():

    SS.push_back(MACHINELIST); // add the MACHIHELIST instance
    SS.push_back(MachineList()); // add a default constructed MachineList.
    

    In your code, MACHINELIST is an instance of type MachineList.

    Edit in response to comments: if you wanted to store pointers, you would need a vector of pointers:

    vector<MachineList*> SS;
    

    Then you can add entries thus:

    MachineList* m = new MachineList;
    SS.push_back(m);
    

    You are responsible for deleting the pointer to deallocate the dynamically allocated resources at the appropriate moment. i would suggest using smart pointers instead of raw ones, but you have more fundamental problems in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you had two snippets: (global-set-key \C-d delete-char) and (define-key global-map \C-d delete-char) Is
Crockford had this example to keep myArray from being in the global scope: var
In classic asp you had the Global.asa file, what's the equivalent in .Net? I
Had to download Command Line Tools from Apple to get make to work, but
Had this working; at one stage. The problem is the following text is now
I had this code @Local interface IRepo { //... } @Stateless class Repo implements
Has anyone else had this issue? I have to be doing something wrong. So
I had this question... answered and very nice it was too. But, oddity has
Looking at some old VB 6.0 code we had created a global mFont variable
Imagine in the Global.asax.cs file I had an instance class as a private field.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.