473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

C++ crash problem...

83
Hi, I have been working on some dll project, just to store values.
I hardly use arrays, so it may be a bit on the stupid side.

Ok, this is the program that uses the dll:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <windows.h>
  5. #include "..\dlltest1\main.h"
  6. using namespace std;
  7. int main()
  8. {
  9.    dll store;
  10.     store.store("hello");
  11.     char *vals = store.getvals(1);
  12.     for (int i = 0; i <= 10; i++) cout << " " << vals[i] << "\n";
  13.       return 0;
  14. }
dll header:

Expand|Select|Wrap|Line Numbers
  1. #ifdef DLLDIR_EX
  2.    #define DLLDIR  __declspec(dllexport)   // export DLL information
  3.  
  4. #else
  5.    #define DLLDIR  __declspec(dllimport)   // import DLL information
  6.  
  7. #endif
  8.  
  9. using namespace std;
  10. class dll
  11. {
  12.     private:
  13.     char storagearray[1000][10][1000];
  14.     static int ammount;
  15.  
  16.    public:
  17.       dll();          
  18.       ~dll();        
  19.     int addto(string string, int loc);
  20.     int store(string string, int loc = 0);
  21.     int add(string thing);
  22.     char* getvals(int loc);
  23. };
and dll main:

Expand|Select|Wrap|Line Numbers
  1. #include <string>
  2. #include "main.h"
  3. #include <iostream>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. dll::dll(){};
  9. dll::~dll(){};
  10.  
  11. int dll::ammount = 1;
  12.  
  13. int dll::addto(string string, int loc){
  14.     if(storagearray[loc][0][0]){
  15.     int x = 2+ storagearray[loc][1][0];
  16.     if(x<8){
  17.         strcpy(storagearray[loc][x],string.c_str());
  18.         storagearray[loc][1][0] = ++x;
  19.         return 0;
  20.     }
  21.     else return 3;
  22.     }
  23.     else return 2;
  24. }
  25.  
  26. int dll::add(string string){
  27.     for(int i = 1; i <= ammount; i++){
  28.         if(storagearray[i][0][0]) continue;
  29.         else { storagearray[i][0][0] = 1;
  30.         int thing = 2+ storagearray[i][1][0]++;
  31.         strcpy(storagearray[i][thing],string.c_str());
  32.         return 1;
  33.         }
  34.         ammount++;
  35.         storagearray[ammount][0][1]++;
  36.         strcpy(storagearray[ammount][2],string.c_str());
  37.         storagearray[ammount][0][0] = 1;
  38.         cout << (char)string.c_str() << " added. \n";
  39.         return 1;
  40.  
  41.     }
  42.     return -1;
  43.     }
  44.  
  45. int dll::store(string string, int loc){
  46.     int done = 0;
  47.     int dloc = 0;
  48. if(loc == 0) dloc = add(string);
  49. else done = addto(string, loc);
  50. if(dloc == -1) return 5;
  51. else return done;
  52. }
  53.  
  54.     char * dll::getvals(int loc){
  55.         char *array;
  56.         if(storagearray[loc][0][0]){
  57.             for(int i = 0; i <= 10; i++){
  58.                 strcpy(array, storagearray[loc][i]);
  59.         }
  60.         }
  61.         return array;
  62.     }
  63.  
  64.  
  65.  


The return value for this is : -1073741571 (0xC00000FD)
It is using the correct object file.

I cant see what the problem is exactly, when building the dll, theres no output errors. But i do have doubts about 'storagearray'.
Oct 25 '08 #1
2 1360
weaknessforcats
9,208 Expert Mod 8TB
What exactly are you trying to do?

A class named dll is very od since an object ios not a dll. Are you trying to create a dll and use it?

I see you mixing C++ strings (string() with C-srrings (char*). Why can't yu use just string objects?

There is a 3D array in your class. C++ programmers generally use a vector instead of an array. Why 3D? If you are attempting to store strings you would have a vector<vector<string> > so I don't see where the third dimiension comes in.

Also that 3D array is very large and is on the stack. Stack memory is not the place for things like this. Again, all this is resolved by using a vector since a vector manages its own memory.
Oct 26 '08 #2
Adam01
83
I was having trouble storing a string in, say, [1][2] - so I assumed that the array was only holding a single value.
so then I used [1][2][1000], and i would copy and string into [1][2], copying the string into [1][2][0-1000], then the crashing came in...

Im making a dll to store stuff (for no reason) .

When I used 2d arrays, they stored values.. wrong, like corrupted.
The translation was working fine (string -> char, char -> string).
Oct 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
8
by: Eric Brunel | last post by:
Hi all, I was creating a Tkinter widget in the style of the reversed tabs below Excel worksheets and I stepped in a serious problem: the code I made makes python crash with a seg fault, bus...
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
14
by: JK Peck | last post by:
I have a fairly large Access application that ran correctly in Access 2000. After upgrading to Access 2003 (and recompiling and updating references), it reliably crashes at a certain point. If I...
9
by: Droopy | last post by:
Hi, I am running an application on 74 PC (1 instance on each PC). This morning, 2 applications crashes. There were neither popup windows signaling it nor dump file created. I only find in the...
12
by: benjamin.krulewitch | last post by:
I'm debugging an issue with a C program that causes the computer to crash, and I'm attempting to log information immediately before the crash occurs. I us my BKprintLog function (see below) to...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
16
by: linq936 | last post by:
Hi, It could be a very simple problem, but i can not see it... Here is the code: char* lower(char* str){ char* p = str; while ( *str ) { *str = tolower(*str); <=====crash! str++;
1
by: Alex | last post by:
Hello everybody, I've been working for days on a "twilight zone" bug and I can't make any sense of it. This is in an application that was developped on XP and that was modified to handle Vista....
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.