|
If the user is passing an array of double 's into your DLL, you should have them pass the number of values in the array as well. That's the only way to ensure that you don't run off the end of the array.
Software Zen: delete this;
|
|
|
|
|
That's what I am doing right now; however, users can be dumb enough to supply an array of 10 values but set the number of attached values to 20.
I guess I can rephrase the question a little bit:
Is there a way to trap UNEXPECTED error in C++? As far as I can see, you can stick in "throw" where you think the application may fail, but is there a way to assign error handling to the whole routine so that no matter where and why it fails there, go to a specific location. For example in VB, it is achieved this way:
On Error GoTo ErrorHandler
....
code
.........
Exit Function
Error Handler:
if err = 12 Then .....
|
|
|
|
|
That IS what exceptions are for in the first place.
You wrap the part you want into try{..} and catch the errors afterwards. There your routine can ask user for help, rectify things and retry or just return.
OR you can write simply throw; and catch one level higher.
The idea is not to brach on some magic numbers, but on the type of the exception object thrown - you can have a whole battery of catch-handlers after one try, and if you oder them from derived to base, you can fine tune what you catch.
try
{
..
}
catch (const std::myFunny_error& e)
{
..
}
catch (const std::runtime_error& e)
{
..
}
catch (const std::exception& e)
{
..
}
catch (...)
{
}
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Try looking up "structured exception handling" in the MSDN. From what I can see, this lets you catch the access violation.
Another way to get around this problem would be to modify your library interface. Suppose your current routine is like this:
void OperateOnArray(int array[], int array_size);
You could change the interface to something like the following:
void StartOperation();
void SetOperationItem(int index,int item);
void DoOperation()
In this case, the array is managed by your library. StartOperation(); initializes the array to the empty condition. SetOperationItem() sets an item in the array, growing it as necessary. Finally, DoOperation() does the operation the original function OperateOnArray(...) did, except it does it on the array your code is managing. If the caller needs to get the array back as part of the results, you could add a corresponding function like:
void GetOperationResult(int index,int *result);
Software Zen: delete this;
|
|
|
|
|
you might also look at IsBadReadPtr and IsBadWritePtr. as the other poster said, it doesn't stop you from running off the end of the array into other legal, but unrelated, chunks of memory; but it will tell you if you're on your way to an access violation or not.
-c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
|
|
|
|
|
Use std::vector instead of plain arrays, and at() instead of [] .
|
|
|
|
|
It's all nice of you to suggest using vector class instead, but how can I use it to pass a list of items from a VB application into a C++ DLL?
With an array of doubles it's possible and easy ...
|
|
|
|
|
std::vector < double > vec;
..fill vec..
Now &vec[0] is a pointer to an array of vec.size() doubles, that you can pass into dlls, or hand over to VB or whatever. You just cant extend or shrink it on the fly. For this you need to use the vector-interface.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
What about the other way around: from VB to C++?
|
|
|
|
|
I have no idea about VB.
But you said your caller gives a number of items and where they are stored, so that you can copy them into a C-Array.
So, simply use resize() to alloate enough space in your std::vector , and copy to the address &vec[0].
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
in this case, you should probably use an actual vector, as in the STL. Then you'd have no problems at all.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
It'd probably be fairly easy to make a bot that'd post random stupid VB questions, and nobody would probably ever notice - benjymous - 21-Jan-2003
|
|
|
|
|
I´m working on a backup service for our customers. Som backup software has an open files option to backup file left opened when the office is left.
How to do that any idea !
|
|
|
|
|
I have rather wide experience, programming using MFC5 (MFC42.dll) with MS VC++ 6.0. Recently I obtained VS .NET. I've made MFC-application, link MFC as static library and run the app on Win98se. Here I was notified about absence of OLEACC.dll although I did not check to use Accessibility API in MFC app wizard. Then I have made a setup project for my app. It included OLEACC.dll and other required files. This time win98se said that it couldn’t run OLEACC.dll, and ask me to check for contents of this library.
Someone ever met such a problem. Is there any way to build my MFC projects with .Net and run them on Win9x/NT/XP? Or I should use VC6 as before?
|
|
|
|
|
For some reason, VC7 apps seem to always link to oleacc.dll. The way around it is to delay loading it (have it load only if and when required).
First you have to link to delayimp.lib.
#pragma comment (lib, "delayimp.lib")
Then set your app settings
Project => Properties => Linker => Advanced => Delay loaded Dll => Support...
Project => Properties => Linker => Input => Delay loaded DLLs => "oleacc.dll"
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
I've never had this problem and I've built many programs with VC++7 MFC using VS.NET. All have worked on 98/ME/NT/2000/XP with one exception: A CFileDialog box didn't work properly on a 98 machine.
Art
|
|
|
|
|
Is there a quick and easy way to insert a new element into an existing CString Array? I'd like to know if there is a function to do this or if I just need to set up a FOR loop.
If I have to use a FOR loop, how do I trap on exceeding the size of the Array?
Thanks!
John Hagen
|
|
|
|
|
Use the CStringArray instead, it provides some handy functions like InsertAt,Add,SetAt,etc..
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi Gregor,
Thanks for the tip. That's what I needed and it works!
John
|
|
|
|
|
When I have a modeless dialog window opened and I hit enter the dialog will dissapear. I don't want that to happen. If I am editing the data in a control and I hit enter I would like the focus to shift as if I pressed tab. I got the following code from this website but I don't understand it. I can't find WM_GETDLGCODE and on top of that I don't want to create a new class just to capture a message.
UINT SMUPPGrid::OnGetDlgCode()
{
UINT result = CListCtrl::OnGetDlgCode();
result = result | DLGC_WANTALLKEYS;
return result;
}
Can someone tell me how to capture 'enter' and shift the focus from one control to another.
none
|
|
|
|
|
Try overriding OnOK .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I don't have an IDC_OK handle to deal with. I have removed that button. How can I override the function when I don't have a handle for it?
none
|
|
|
|
|
Just add a new function called OnOK() in your dialog-class. And be sure not to call CDialog::OnOK()
--
karl
|
|
|
|
|
You can modify how the enter key works by overriding the virtual function PreTranslateMessage()
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
pMsg->wParam = VK_TAB;
this will cause all ENTER keys to be treated as TABs
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
I am pretty new at C++ but hello world is pretty far behind me...i can do a lot more than that. Not much, but more. What do i need to know and how much work and how long will it take me to make a good looking 3D shooter with all the DirectX 9 and Cg stuff in it?
|
|
|
|
|
A couple of years, I reckon. The world is full of people who have figured out what a class is, and set out to write games. Check out the game dev sites, they are full of people 'starting the worlds best 3D engine'.
Take a sensible approach. Think about what a game needs, and create projects for yourself to learn those things. Be prepared to scrap 50% of what you learn of the current version of DX in order to use the new version that will come out while you are learning. Try to learn stuff that is more mundane, like data structures/STL/etc. first. Then write a 2D game. Write some 3D demos to experiment with 3D space and physics. Then you might be ready. Even then, remember that a commercial game takes a team of people a good year to write as a full time job.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
It'd probably be fairly easy to make a bot that'd post random stupid VB questions, and nobody would probably ever notice - benjymous - 21-Jan-2003
|
|
|
|