Avatar of zeurx
zeurxFlag for United States of America

asked on 

return a value

OK guys, get this and get all my points i currently have...

A program runs fine in an IDE under debug, but when you execute it from exporer the just in time debugger kicks in but does not break in ASM.  Also it only has a problem when loading a dll.


[Edit Code Snips following]
I have found that when i return an LPCTSTR is when it crashes, still do not understand why it will work when ran from the IDE

Plugin.DLL
LPCTSTR *Initialize()
{
      // Initialize plugin
      args = new LPCTSTR;
      args[BCONNECT] = "Connect"; //Connect button text
      args[BDISCONNECT] = "Disconnect"; //Disconnect button text
      args[MAP] = "MapDrive";
      args[UNMAP] = "UnMapDrive";
      args[DOMAIN] = "DOMAIN";
      // Drive letter and server, 2 slots per network drive
      int NumOfDrives = 1; //The number of network drives
      Drives = new LPCTSTR;
      Drives[0] = "Z:"; //Drive letter to use
      Drives[1] = "localhost"; //Server to use
      Drives[2] = "127.0.0.1"; //Fallback IP
      // Add drives and servers to main array
      for(int i = 0; i <= NumOfDrives*3-1; i++)
      {
            args[DRIVES+i] = Drives[i];
            args[DRIVES+i+1] = NULL;
      }
      
      return args;
}

Program.exe
typedef LPCTSTR *(*Initialize)(void);
Initialize Init = (Initialize)::GetProcAddress(PlugDll,"Initialize");
if(!Init)
{
      MessageBox("Failed to initialize",0, MB_ICONERROR);
      break;
}
// Setup local vars
DriveArgs = NULL;
DriveArgs = new LPCTSTR;
// Call initialize function
break;
DriveArgs = Init();

Now if i break before i call the dll function my program wont crash so i know it is that function on the dll. could it be the returning of the LPCTSTR *args?
System ProgrammingC++

Avatar of undefined
Last Comment
itsmeandnobodyelse
Avatar of grg99
grg99

Er, isnt a LPCTSTR  a pointer to a TCHAR string?

Then you assign values to the array elements.

But I don't see any dimension for the LPCTSTR ??

I suspect you need to allocate some real memory for the elements.



Avatar of zeurx
zeurx
Flag of United States of America image

ASKER

how do you allocate memory? LPCTSTR myvar[255] but then how to i make the function returnable
SOLUTION
Avatar of Deepu Abraham
Deepu Abraham
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of zeurx
zeurx
Flag of United States of America image

ASKER

problem solved by adding the [size] at the end of each new LPCTSTR statements
>>>> by adding the [size] at the end of each new LPCTSTR statements

I hope you omitted the drives array. It really makes no sense. If you would post your last code we could check if now is all correct.

Regards, Alex
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo