Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DLL causing application error

Posted on 1999-07-15
7
Medium Priority
?
216 Views
Last Modified: 2010-05-18
I developed a DLL using VC++. Since I need CString to do string manipulation, I did this by using the MFC Application DLL example that the wizard creates, added a few functions of my own, then export the functions that needed to be exported.
When I try this DLL by calling it in a VB test program (what it was written for), I could call it over and over again without any problem. But as soon as I use it in a VB program with DataEnvironment queries, after a few times of calling, I get an application error message:

The instruction at "0x77f64765" referenced memory at "0x31343534". The memory could not be "written".

Or something similar. When I don't call the DLL I don't have any problem running that program. That's why I suspect my DLL is causing it. But I don't know how to debug it.

In my DLL I'm not doing any memory allocation. I pass a string to it, and write a string value to the location provided to it. The header looks something like this:

int __stdcall EncryptText(LPSTR inStr, LPSTR *poutStr)

*poutStr points to a VB string with 255 spaces. I'm not re-allocating spaces but just writing the result to that space. My believe is VB will clean it up probably.

Can someone please tell me how to go about debugging it? Thanks a lot.
0
Comment
Question by:jluck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 1200266
As you're using a MFC DLL from a non-MFC (i.e. VB) application, you'll have to 'embrace' the functions' bodies inside the DLL with 'AFX_MANAGE_STATE()', e.g.

int __stdcall EncryptText(LPSTR inStr, LPSTR *poutStr)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));

//...
}

0
 

Author Comment

by:jluck
ID: 1200267
Thanks jkr.

That's something I forgot. However that's not it. I'm still getting the same error message. Infact I just rewrote the entire thing to use stand C++ string instead of MFC CString, so no MFC's. But still giving me access violation. Any way to debug it?
0
 
LVL 2

Expert Comment

by:jonalee
ID: 1200268
You all your function from VB? I think the error is not you VC's. It the issue of exchange data between VB and VC. Have you call your DLL function from your test VC app? If this is OK, then that means the error is really VB's.
Normally, exchange string between VB and VC, you need to use BSTR (for incoming) and BSTR* (for outcoming)


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:jonalee
ID: 1200269
You all your function from VB? I think the error is not you VC's. It the issue of exchange data between VB and VC. Have you call your DLL function from your test VC app? If this is OK, then that means the error is really VB's.
Normally, exchange string between VB and VC, you need to use BSTR (for incoming) and BSTR* (for outcoming)

Also, if only for VB, why write DLL, try ActiveX. VB loves much of this.



0
 
LVL 2

Expert Comment

by:jonalee
ID: 1200270
You all your function from VB? I think the error is not you VC's. It the issue of exchange data between VB and VC. Have you call your DLL function from your test VC app? If this is OK, then that means the error is really VB's.
Normally, exchange string between VB and VC, you need to use BSTR (for incoming) and BSTR* (for outcoming)

Also, if only for VB, why write DLL, try ActiveX. VB loves much of this.



0
 
LVL 1

Accepted Solution

by:
kdkd earned 400 total points
ID: 1200271
VB has Problems wit C++: Two Alternatives:
1) Write a Comserver with an IDispatch Interface
2) Do not use c++, use c!!!!! use only releasebuild.. that should work
0
 

Author Comment

by:jluck
ID: 1200272
Thank you all. I'd appreciate if kdkd you can tell me what are the problems you mentioned in your answer. Just want to learn from my mistake.

I'm now using ActiveX DLL, like jonalee suggested. Seems like it's working better.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question