Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 844
  • Last Modified:

Calling fopen in DLL called from VB?

We've written a 16 bit DLL in C++ that opens file using the MFC CStdioFile and CFile classes.  These use the fopen C
runtime library function and the _dos_open library
function respectively.

The problem is that when this DLL is called from an Access
Basic (V2)application or a VB (V4) application that has an
Access database open, the opens of CStdioFile
objects sometimes fail.  The m_cause member of
the associated CFileException object returns a 1
(generic) and the m_lOsError member contains 0.

The problem does not occur when called from a non-Access
VB application or from applications written in C++ (no
Access).

At the time of the failure, the DLL has only one other
file open (CStdioFile) and is trying to open another
CStdioFile.

The problem occurs in both Windows 3.x and Win95.

I found one short and unresolved thread on what sounded
like the same problem. One contributor pointed to a MSDN
article entitled "Creating Custom Add-in Libraries for
Word 6.0 Using the Word API."  This article suggests that
using text mode DOS file handles is not guaranteed to work
in a DLL called from Word.  The author of the referencing
newsgroup message suggested that this may be true for
VB and Access Basic as well.  While this might explain
the behaviour, I am skeptical.

Thanks.
0
NickDanger
Asked:
NickDanger
1 Solution
 
ajh020797Commented:
If the problem is purely with text files, why fopen with the binary flag set and remember to put \r\n instead of \n ?
0
 
NickDangerAuthor Commented:
Thanks ajh!
I was looking for an explanation however.  I've since been
able to "fix" the problem, by increasing the file handle
count in my DLL (ala MSDN article "Increasing File Handles"
found in section 2.7 of the Runtime Library Reference).

While this seems to have fixed the problem, I am still troubled
since I cannot explain it.

Thanks again.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now