Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Simple Unresolved External Symbol error Pin
Stuart Dootson29-Jun-09 22:23
professionalStuart Dootson29-Jun-09 22:23 
GeneralRe: Simple Unresolved External Symbol error Pin
Member 470553830-Jun-09 5:59
Member 470553830-Jun-09 5:59 
GeneralRe: Simple Unresolved External Symbol error Pin
Stuart Dootson30-Jun-09 6:04
professionalStuart Dootson30-Jun-09 6:04 
AnswerRe: Simple Unresolved External Symbol error Pin
Aric Wang29-Jun-09 23:30
Aric Wang29-Jun-09 23:30 
QuestionCan a data from a file be directly stored in a structure in C? Pin
Razanust29-Jun-09 16:25
Razanust29-Jun-09 16:25 
AnswerRe: Can a data from a file be directly stored in a structure in C? Pin
Harsh Shankar29-Jun-09 18:43
Harsh Shankar29-Jun-09 18:43 
AnswerRe: Can a data from a file be directly stored in a structure in C? Pin
CPallini29-Jun-09 21:40
mveCPallini29-Jun-09 21:40 
QuestionC++ pointers and DLL linking Pin
dAvId_BotMan29-Jun-09 16:06
dAvId_BotMan29-Jun-09 16:06 
Hello, I'm David. Recently I've been working on a project... A robot that can be controlled locally by a Xbox360 controller, and eventually will be controlled remotely the same way. To control the motors on the robot I have to link with a DLL, and so far it works for a bit, but soon after starting the app it is closed for Access Violations. This issue deffinately envolves the definitions and pointers and such to the DLL... What is going wrong, and how can i prevent it from happening?

Thanks, David Kirby

/*-----------------------------------------------------------------------------------------------*/

#include "CXBOXController.h"
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include <cstdlib>
typedef bool     (*Type_InitMotoBee)();                                       
typedef bool     (*Type_SetMotors)(int on1, int speed1, int on2, int speed2, int on3, int speed3, int on4, int speed4, int servo);
typedef void     (*Type_Digital_IO)(int *inputs, int outputs);
using namespace std;

HINSTANCE MHtbDLL=LoadLibrary(_T("mtb.dll"));

CXBOXController* Player1;
int main(int argc, char* argv[])
{
     Player1 = new CXBOXController(1);
     system("Color 02");
      system("title LANbot Host - Local Motor Control Trial");

      cout << "      __      _            __ _               _            |\n"
          << "      / /   /_\\      /\\ \\ \\ |__   ___ | |_         |\n"
            << "   / /   //_\\\\   /   \\/ / '_ \\ / _ \\| __|      |\n"
            << "   / /___/   _   \\/ /\\   /| |_) | (_) | |_         |\n"
            << "   \\____/\\_/ \\_/\\_\\ \\/ |_.__/ \\___/ \\__| 2009|\n"
            << "--------------------------------------------\n\n";
      //End Title Bar
     if(MHtbDLL != NULL){cout << "\tMtb.dll Loaded Successfuly...";}
     if(MHtbDLL == NULL)
          {
               cout << "\tMtb.dll did NOT load Successfuly!\n"
                    << "\tCheck to see that Mtb.dll is in the same\n"
                    << "\tdirectory as this executable.\n\n"
                    << "\tPress [Enter] to Continue...";
               cin.get();
          }
      Sleep(1000); system("cls");
    
     int speed = 1;
     int gR = 128;
     int button=0;    

     Type_InitMotoBee InitMotoBee;
     Type_SetMotors SetMotors;
     Type_Digital_IO Digital_IO;

     InitMotoBee = (Type_InitMotoBee)GetProcAddress(MHtbDLL, "InitMotoBee");
     SetMotors = (Type_SetMotors)GetProcAddress(MHtbDLL, "SetMotors");
     Digital_IO = (Type_Digital_IO)GetProcAddress(MHtbDLL, "Digital_IO");
    
     InitMotoBee();

     while(true)
     {
          if(Player1->IsConnected())
               {              
    
               //Set both motors Foward
               if(Player1->GetState().Gamepad.sThumbLY > 5001
                    && Player1->GetState().Gamepad.sThumbLX > -4999
                    && Player1->GetState().Gamepad.sThumbLX < 4999
                    && button==0)
               {
                         SetMotors(1,gR,0,0,1,gR,0,0,0);
                         button=1;
                   
                    while(Player1->GetState().Gamepad.sThumbLY > 5001
                         && Player1->GetState().Gamepad.sThumbLX > -4999
                         && Player1->GetState().Gamepad.sThumbLX < 4999
                         && button==1)
                    {
                         cout << "\n\n\t\t\tFOWARD\n";
                         system("cls");
                    }
                         button=0;
                         SetMotors(0,0,0,0,0,0,0,0,0);
               }
              
               //Set Right motor foward, turn Left
               if(Player1->GetState().Gamepad.sThumbLY > 5001
                    && Player1->GetState().Gamepad.sThumbLX < -4999
                    && button==0)
               {
                    SetMotors(1,gR,0,0,0,0,0,0,0);
                    button=1;
                    while(Player1->GetState().Gamepad.sThumbLY > 5001
                              && Player1->GetState().Gamepad.sThumbLX < -4999
                              && button==1)
                    {
                        
                         cout << "\n\n\t\t\tFOWARD, LEFT TURN\n";
                         system("cls");
                    }
                         button=0;
                         SetMotors(0,0,0,0,0,0,0,0,0);
               }
              
               //Set Left Motor Foward, turn Right.
               if(Player1->GetState().Gamepad.sThumbLY > 5001
                    && Player1->GetState().Gamepad.sThumbLX > 4999
                    && button==0)
               {
                    SetMotors(0,0,0,0,1,gR,0,0,0);
                    button=1;
                    while(Player1->GetState().Gamepad.sThumbLY > 5001
                    && Player1->GetState().Gamepad.sThumbLX > 4999
                    && button==1)
                    {
                         cout << "\n\n\t\t\tFOWARD, TURN RIGHT\n";
                         system("cls");
                    }
                    button=0;
                    SetMotors(0,0,0,0,0,0,0,0,0);
               }
              
               //Set both motors in reverse
               if(Player1->GetState().Gamepad.sThumbLY < -5001
                    && Player1->GetState().Gamepad.sThumbLX > -4999
                    && Player1->GetState().Gamepad.sThumbLX < 4999
                    && button==0)
               {
                    SetMotors(0,0,1,128,0,0,1,128,0);
                    button=1;
                    while(Player1->GetState().Gamepad.sThumbLY < -5001
                    && Player1->GetState().Gamepad.sThumbLX > -4999
                    && Player1->GetState().Gamepad.sThumbLX < 4999
                    && button==1)    
                    {
                         cout << "\n\n\t\t\tREVERSE\n";
                         system("cls");
                    }
                    button=0;
                    SetMotors(0,0,0,0,0,0,0,0,0);
               }

               //Reverse Right motor
               if(Player1->GetState().Gamepad.sThumbLY < -5001
                    && Player1->GetState().Gamepad.sThumbLX < -4999
                    && button==0)
               {
                    SetMotors(0,0,1,128,0,0,0,0,0);
                    button=1;
                    while(Player1->GetState().Gamepad.sThumbLY < -5001
                    && Player1->GetState().Gamepad.sThumbLX < -4999
                    && button==1)
                    {
                         cout << "\n\n\t\t\tREVERSE, TURN LEFT\n";
                         system("cls");
                    }
                    button=0;
                    SetMotors(0,0,0,0,0,0,0,0,0);
               }

               //Reverse Left Motor
               if(Player1->GetState().Gamepad.sThumbLY < -5001
                    && Player1->GetState().Gamepad.sThumbLX > 4999
                    && button==0)
               {
                    SetMotors(0,0,0,0,0,0,1,128,0);
                    button=1;
                    while(Player1->GetState().Gamepad.sThumbLY < -5001
                    && Player1->GetState().Gamepad.sThumbLX > 4999
                    && button==1)
                    {
                         cout << "\n\n\t\t\tREVERSE, TURN RIGHT\n";
                         system("cls");
                    }
                    button=0;
                    SetMotors(0,0,0,0,0,0,0,0,0);
               }

               //Spin Right
               if(Player1->GetState().Gamepad.sThumbLX > 5001
                    && Player1->GetState().Gamepad.sThumbLY < 4999
                    && Player1->GetState().Gamepad.sThumbLY > -4999
                    && button==0)
               {
                    SetMotors(0,0,1,gR,1,gR,0,0,0);
                    button=1;
                    while(Player1->GetState().Gamepad.sThumbLX > 5001
                    && Player1->GetState().Gamepad.sThumbLY < 4999
                    && Player1->GetState().Gamepad.sThumbLY > -4999
                    && button==1)
                    {
                         cout << "\n\n\t\t\tSPIN RIGHT\n";
                         system("cls");
                    }
                    button=0;
                    SetMotors(0,0,0,0,0,0,0,0,0);
               }

               //Spin Left
               if(Player1->GetState().Gamepad.sThumbLX < -5001
                    && Player1->GetState().Gamepad.sThumbLY < 4999
                    && Player1->GetState().Gamepad.sThumbLY > -4999
                    && button==0)
               {
                    SetMotors(1,gR,0,0,0,0,1,gR,0);
                    button=1;
                    while(Player1->GetState().Gamepad.sThumbLX < -5001
                    && Player1->GetState().Gamepad.sThumbLY < 4999
                    && Player1->GetState().Gamepad.sThumbLY > -4999
                    && button==1)
                    {
                         cout << "\n\n\t\t\tSPIN LEFT\n";
                         system("cls");
                    }
                    button=0;
                    SetMotors(0,0,0,0,0,0,0,0,0);
               }

               //Angle Servo up
               if(Player1->GetState().Gamepad.sThumbRY > 5000)
               {
                    cout << "\n\n\t\t\tCAMERA UP\n";
                    system("cls");
               }

               //Angle Servo Down
               if(Player1->GetState().Gamepad.sThumbRY < -5000)
               {
                    cout << "\n\n\t\t\tCAMERA DOWN\n";
                    system("cls");
               }
              
               //Stop Motors
               if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB)
               {
                    SetMotors(0,0,0,0,0,0,0,0,0);
                    cout << "STOPPED";
                    system("cls");
               }

               //Gear One
               if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A)
               {
                    speed=1; gR=128;
                    while(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A)
                    {
                         cout << "\n\n\t\t\tShifting. You are now in gear " << speed << ".\n";
                         system("cls");
                    }
               }
               //Gear Two
               if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B)
               {
                    speed=2; gR=189;
                    while(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B)
                    {
                         cout << "\n\n\t\t\tShifting. You are now in gear " << speed << ".\n";
                         system("cls");
                    }
               }
               //Gear Three
               if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_Y)
               {
                    speed=3; gR=250;
                    while(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_Y)
                    {
                         cout << "\n\n\t\t\tShifting. You are now in gear " << speed << ".\n";
                         system("cls");
                    }
               }
              
               /*if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_START)
               {
                    SetMotors(0,0,0,0,0,0,0,0,0);
                    int brake=1;
                    cout << "BRAKE";
                    while(brake==1)
                    {
                         if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_START)
                         {
                              brake++;
                         }
                    }
                    system("cls");
               }*/

               //Exit Loop (break;)
               if(Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_BACK)
               {
                    system("cls");
                    cout << "\n\n\tUnloading library...\n";
                    FreeLibrary(MHtbDLL);
                    Sleep(1000);
                    if(MHtbDLL!=NULL){cout << "\n\n\tMtb.dll Did NOT Unload Successfuly!";}
                    if(MHtbDLL==NULL){cout << "\n\n\tMtb.dll Unloaded Successfuly...";}
                    Sleep(1000);
                    break;
               }
              
          }
         
          //Controller Not present
          else
          {
               cout << "\n\t\t\tWhere is the controller? o.0\n";
               cout << "\t\t\t   Press [ENTER] To Exit.";
               cin.get();
               system("cls");
               cout << "\n\n\tUnloading library...\n";
               FreeLibrary(MHtbDLL);
               Sleep(1000);
               if(MHtbDLL!=NULL){cout << "\n\n\tMtb.dll Did NOT Unload Successfuly!";}
               if(MHtbDLL==NULL){cout << "\n\n\tMtb.dll Unloaded Successfuly...";}
               Sleep(1000);
               break;
          }
     }
     delete(Player1);

     return( 0 );
}
       

<code></code><code></code><pre></pre>
AnswerRe: C++ pointers and DLL linking Pin
«_Superman_»29-Jun-09 18:54
professional«_Superman_»29-Jun-09 18:54 
QuestionRe: C++ pointers and DLL linking Pin
dAvId_BotMan29-Jun-09 19:08
dAvId_BotMan29-Jun-09 19:08 
AnswerRe: C++ pointers and DLL linking Pin
«_Superman_»29-Jun-09 19:16
professional«_Superman_»29-Jun-09 19:16 
QuestionRe: C++ pointers and DLL linking Pin
dAvId_BotMan29-Jun-09 19:20
dAvId_BotMan29-Jun-09 19:20 
AnswerRe: C++ pointers and DLL linking Pin
«_Superman_»29-Jun-09 19:25
professional«_Superman_»29-Jun-09 19:25 
GeneralRe: C++ pointers and DLL linking Pin
dAvId_BotMan29-Jun-09 19:35
dAvId_BotMan29-Jun-09 19:35 
AnswerRe: C++ pointers and DLL linking Pin
Pavan_Putra29-Jun-09 20:06
Pavan_Putra29-Jun-09 20:06 
QuestionKeyboard Hook - all in a DLL Pin
trungkiendt829-Jun-09 8:09
trungkiendt829-Jun-09 8:09 
AnswerRe: Keyboard Hook - all in a DLL Pin
«_Superman_»29-Jun-09 18:48
professional«_Superman_»29-Jun-09 18:48 
GeneralRe: Keyboard Hook - all in a DLL Pin
trungkiendt829-Jun-09 18:56
trungkiendt829-Jun-09 18:56 
GeneralRe: Keyboard Hook - all in a DLL Pin
«_Superman_»29-Jun-09 19:03
professional«_Superman_»29-Jun-09 19:03 
GeneralRe: Keyboard Hook - all in a DLL Pin
trungkiendt830-Jun-09 11:34
trungkiendt830-Jun-09 11:34 
QuestionProblems showing a non modal form from a VB6 activex in Visual C++ 6 [modified] Pin
AlexandreT-DC29-Jun-09 6:09
AlexandreT-DC29-Jun-09 6:09 
QuestionLOGFONT structure.. Pin
kumar sanghvi29-Jun-09 5:23
kumar sanghvi29-Jun-09 5:23 
AnswerRe: LOGFONT structure.. Pin
Chris Losinger29-Jun-09 5:45
professionalChris Losinger29-Jun-09 5:45 
GeneralRe: LOGFONT structure.. Pin
kumar sanghvi29-Jun-09 7:49
kumar sanghvi29-Jun-09 7:49 
GeneralRe: LOGFONT structure.. Pin
Chris Losinger29-Jun-09 7:54
professionalChris Losinger29-Jun-09 7:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.