CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2009
    Posts
    18

    Declaration of office

    I have a function in the header Form1.h calling from Motory.cpp.
    But not me refer to it.
    Do you know what toje?

    Declaration:
    Motory.cp :

    #pragma warning(disable : 4996) // Disable warnings about some functions in VS 2005
    #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

    #include "stdafx.h"

    #include <stdio.h>
    #include <tchar.h>
    #include <conio.h>
    #include <process.h>
    #include "USMCDLL.h"
    #include "Form1.h"

    using namespace System;
    using namespace System::Runtime::InteropServices;
    using namespace System::Windows::Forms;
    using namespace Motory_2;

    void zapisListBox1(DWORD,char*,char*);
    //-----------------------------------------------------

    void PrintDevices(USMC_Devices &DVS)
    {
    for(DWORD i = 0; i < DVS.NOD; i++)
    {
    zapisListBox1(i, DVS.Serial[i], DVS.Version[i]);
    }
    }


    Declaration Form1.h :

    void zapisListBox1(DWORD i, char* Serial, char* Version)
    {
    this->listBox1->Items->Add("Device - "+(i+1)+",\tSerial Number - "+Convert::ToString(Serial)+",\tVersion - "+Convert::ToString(Version));
    }


    Error:
    Motory_2.obj : error LNK2028: unresolved token (0A000020) "void __clrcall zapisListBox1(unsigned long,char *,char *)" (?zapisListBox1@@$$FYMXKPAD0@Z) referenced in function "void __clrcall PrintDevices(struct USMC_Devices_st &)" (?PrintDevices@@$$FYMXAAUUSMC_Devices_st@@@Z)


    Motory_2.obj : error LNK2019: unresolved external symbol "void __clrcall zapisListBox1(unsigned long,char *,char *)" (?zapisListBox1@@$$FYMXKPAD0@Z) referenced in function "void __clrcall PrintDevices(struct USMC_Devices_st &)" (?PrintDevices@@$$FYMXAAUUSMC_Devices_st@@@Z)


    C:\Documents and Settings\Brabčรกček\Dokumenty\Visual Studio 2008\Projects\Motory_2\Debug\Motory_2.exe : fatal error LNK1120: 2 unresolved externals



    Thank you for your help!!

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Declaration of office

    zapisListBox1 is Form1 class method, and not global function. You need to call it having Form1 instance reference.

  3. #3
    Join Date
    Jun 2009
    Posts
    18

    Re: Declaration of office

    Quote Originally Posted by Alex F View Post
    zapisListBox1 is Form1 class method, and not global function. You need to call it having Form1 instance reference.

    You mean like this? but it throws me an error too.

    Form1::zapisListBox1(i, DVS.Serial[i], DVS.Version[i]);


    error:

    .\Motory_2.cpp(53) : error C3767: 'Motory_2::Form1::zapisListBox1': candidate function(s) not accessible

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Declaration of office

    No, you need Form1 instance for this. It looks like you started to work with C++/CLI without C++ experience. I suggest you to learn C++ first.

    In Motory.cpp you need to have variable of type Form1^, which must be initialized to existing Form1 reference. Having this reference, you can call class methods. I cannot show exactly how to do this, because I don't know your program structure.

  5. #5
    Join Date
    Jun 2009
    Posts
    18

    Re: Declaration of office

    Quote Originally Posted by Alex F View Post
    No, you need Form1 instance for this. It looks like you started to work with C++/CLI without C++ experience. I suggest you to learn C++ first.

    In Motory.cpp you need to have variable of type Form1^, which must be initialized to existing Form1 reference. Having this reference, you can call class methods. I cannot show exactly how to do this, because I don't know your program structure.
    How do I create a global pointer to Form1, which provide access to its methods?

    I tried: public: System:: Windows:: Forms:: Form ^ Fun;

  6. #6
    Join Date
    Jun 2009
    Posts
    18

    Thumbs up Re: Declaration of office

    To Alex F Thank you very much... This problem is sort out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured