Exe file wont open!

Pages: 12
Hi there,

I have a previous post about array / random texts which I was able to write some code that works:
http://www.cplusplus.com/forum/windows/140035/

This idea of displaying random text in a label is actually an 'add-on' to a bigger program that functions well.

This program has been placed on my work's network drive. Prior to adding on this 'add - on', the program worked on all computers. However, once updated the code (only the array code seen in the above link), re-compiled it then replaced the exe file on the network, the file doesn't open for any other computer other than mine!

So, the new program that now has this array will only work on my computer.... I hope you understand what I'm trying to say here. It's weired!

Can anyone suggest possible problems / solutions?

Cheers,
You could you be missing C++ runtime libraries? Use depends to see what DLLs your program requires on Windows.
http://www.dependencywalker.com/
Hi kbw,

Thanks again for your help! Much appreciated.

Our work computers, and the computer that I use use Windows 7. DependencyWalker came up with two error messages:

Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

Another states that:

IESHIMS.DLL - Error opening file. The system cannot find the file specified (2).

Not sure what this means other than the *.dll not being found on my computer or on my work's network etc. But why does it still work on my computer but not others? If it is a matter of downloading this *.dll and placing it where it needs to go, i'm pretty sure my work's IT boss won't allow it....

Cheers,
Last edited on
Here's some extra information C++ users...

1. When the program runs (on my computer which runs fine) I get the following output error message:

warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data

Despite this message, the program complies and works normally, at least on my computer.

2. The addition that I refer to above uses two includes:
1
2
#include <string>
#include <ctime> 


and the random text code:
1
2
3
4
5
6
7
8
9
array<String^> ^ Colour = gcnew array<String^>(5);
Colour[0] = "Red";
Colour[1] = "Blue";
Colour[2] = "Yellow";
Colour[3] = "Green";
Colour[4] = "Purple";

srand(time(NULL));
label1->Text = Colour[rand()%5];


If I comment these sections of code out, the exe's file size reduces by nearly 1000kb! I'm out of my depth here understanding what's going on..

Cheers,

Last edited on
I haven't used C# since 2.0 and now know next to nothing about it.

I expect you've pulled in some kind of C# library. Do you need to use C# of can just use C++?
Hi mate,

I have never used C#. The program is 100% C++\CLI and I'm certain that I haven't brought in an additional libraries etc. everything that I have done so far is fairly standard with respected to developing form applications. I'm using VC++2010. Is there an alternate way to generate random text? I just think that it is odd that this odd behaviour has only occurred since adding the above code. The program actually doesn't need it but having this feature would have been nice.

Thanks
Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <vector>
#include <string>
#include <cstdlib>

int main()
{
  std::vector<std::string> randoms;
  std::vector<std::string> colors;
  colors.push_back("red");
  colors.push_back("blue");
  colors.push_back("yellow");
  colors.push_back("green");
  colors.push_back("purple");
  int however_many_random _colors_you_want=3; //example number
  for(int i=0;i<however_many_random_colors_you_want;i++)
  {
    randoms.push_back(colors[rand() % 4]
    // pick a random number 0-4 (because vectors start at 0 like chars)
    // and send the color of the index (the random number) to the back of the randoms vector.
  }
  return 0;
}
Last edited on
Hi Homberto,

Thanks for your help / suggestion.

I've placed your suggested code into my program. But no display of random text. Where do I need to place the label1->Text = ..... or cout<< if it is a console program? I tried label1->Text = randoms.push..... but came up with errors. Like arrays, I've never had to use vectors so this is new to me.

Thanks again,
The program is 100% C++\CLI
That CLI is .Net and you're using Microsoft extensions to use it. It's not C++.
if you want to output it:

for a console program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <vector> //std::vectors
#include <string>  //std::strings
#include <cstdlib> //rand() function
#include <iostream> //std::cout and std::endl

int main()
{
  std::vector<std::string> randoms;
  std::vector<std::string> colors;
  colors.push_back("red");
  colors.push_back("blue");
  colors.push_back("yellow");
  colors.push_back("green");
  colors.push_back("purple");
  int however_many_random _colors_you_want=3; //example number
  for(int i=0;i<however_many_random_colors_you_want;i++)
  {
    randoms.push_back(colors[rand() % 4]
    // pick a random number 0-4 (because vectors start at 0 like chars)
    // and send the color of the index (the random number) to the back of the randoms vector.
    std::cout << randoms[i]; //output all the randoms at once.
    std::cout << randoms[i] << " "; //output all the randoms with a space in between each
    std::cout << randoms[i] << std::endl; //output all the randoms with a line break after each
    //note:  std::endl is pretty much the same as "\n"
  }
  std::cout << randoms[0] << std::endl << randoms[1] << std::endl; //output the first two randoms with a line break after each.
  return 0;
}


what is the data type of label1->Text ?

remember: both std::vector's were declared of the data type std::string. that means randoms[0] is a string and colors[0] is also a string. same with 1, 2, etc.

oh, just noticed this but randoms.push_back(the_string) adds the string to the end of the vector.

vectors are structured sorta like arrays....

myVector:
element0 | element1 | element2

if you do myVector.push_back(element3) myVector will be structured like this:

myVector:
element0 | element1 | element2 | element3

to undo vector.push_back(parameter) use vector.pop_back().

doing myVector.pop_back() (no parameters!) will return the structure to:

myVector:
element0 | element1 | element2

so label1->Text=randoms.push_back(); will not work. try label1->Text=randoms[0]. this will store the first random number as label1->Text.

---

And just for future reference, if you ever need a vector-like-thing of multiple data types, #include <tuple> and use std::tuple. Like this:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//using std::tuples in function form and variable form:

#include <tuple>
#include <string>

std::string err;
int number1 = 7;
int errno;

int main()
{
  std::tuple<int, std::string> myFunction(int number)
  {
    if(number==1)
    {
      errno=0;
      err="No error";
    }
    else
    {
      errno=1;
      err="wrong number";
    }
    return std::make_tuple(errno, err);
  }

  std::tuple<int, std::string> result = myFunction(7);

  return 0;
}
Last edited on
Hi kbw and Homberto,

Thanks for your replies.

kwb, sorry for the incorrectness. I did mean this (.Net) but didn't say it right. I.e. I understand that the coding is 'managed' (I think that's the correct terminology) and not 'real' C++ coding. To try and understand new concepts, I usually write a C++ console version before using WinForm. This is so that I learn both versions of code. WinForms is what my actual program uses as this is what's most familar by my workplace.

Being new to programming, I'm unsure of the correct terminology at times. Thanks for picking up on this.

Homberto,
Thanks for the example code. I will try this a little later today (busy at work at the moment). I tried the label1->Text = random but didn't have the [0] at the end.

Thanks!
But label1->Text is a std::string right?
Hi Homberto,

To be honest, I'm not 100% sure... This is where my terminolgy fails me. I think it is. For example, the 'test' program I'm working on for this random thing before I transfer it to the actual program is just a form and a lable. When the form loads, the label's text changes. I'm prettuy sure that it's just a String^......
then you'll have to do it this way:

1
2
3
4
5
6
//btw you dont need to include any additional headers to do this
//but you must compile with /clr
//but do this because im not familiar with the String^ stuff:
using namespace System;
std::string L1_text = randoms[0]; // assign a string with the first random color
label1->Text=gcnew String(L1_text.c_str());


more here:
http://msdn.microsoft.com/en-us/library/ms235219.aspx
Last edited on
o answer your original question, all users that you want to run your program MUST have Microsoft .NET 4.0 Redistributable installed on their machine first. Only windows 8 users have it installed by default.
Hi Homberto and modoran,

Thanks for this information, Modoran. I asked the IT boss at work and he said that this is more than likely the cause. Most systems run Windows 7. Installing VC++2010 on my PC obviously provided me with .NET 4.0.

I tried placing your code into my code, Homberto but it just displays 'Blue'. In other words, its not random. I've tried changing various elements of the code but it wont randomise. It does, however, show the string within the vector as a text! Whereas, before this wasn't happening. I'll keep trying!

Cheers,
It is random! It displays blue because label1->Text is set to the first random number (randoms[0])

See what happens if you replace that 0 with 1 or 2
Hi Homberto,

Sorry if I wasn't clear. With the current code with randoms[0] the program makes the label say 'blue'. This occurs every time when the program is run. Remember that this code is activated in the form load event. If I change the number it will go to green for example. Same thing, every time this is run, the same
Color is seen. I need this to change the text randomly every time the program is run. Get first time might be red, second time might be blue and so on.
Last edited on
Is there some event or timer that could cause the code to rerun?

like this example: (sorry it's in javascript, easier to show events)
1
2
3
4
window.onLoad=function()
{
document.getElementById("The_Id_Of_A_HTML_Element").onClick=alert("Alert!");
};


This takes the HTML Element with the ID The_Id_Of_A_HTML_Element and every time that the user clicks it creates a javascript popup saying "Alert!"

the code for alert() reruns after each click.

Is there some event you could add to cause it to rerun?
Hi Homberto,

Thanks for this. I tried changing the event in which this code is activated. It works for example, with a button click but not with the Form load event for some reason.

I also tried this on my actual program. Again, it loads with the colour Blue displayed every time. But my program runs quite a number of other Forms, overall acting like a webpage. I.e. clicking various buttons will load a different form and so on. These new forms have a 'return to main page' button. This page is where the random label feature is. When this button is clicked, the label changes.

I'm thinking there's an issue with the Form_Load event and the code. The previous code that worked on my pc but not others (due to not having .Net 4.0) works with the Form_Load event.

Interesting....
Pages: 12