473,777 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dll to read a file and return the number of lines in the file.

52 New Member
following is the code for dll to read a file and return the number of lines in the file.
filedll.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include<iostream>
  3. #include<windows.h>
  4. #include<fstream>
  5. #include<string>
  6. using namespace std;
  7.  
  8. BOOL APIENTRY DllMain( HANDLE hModule, 
  9.                        DWORD  ul_reason_for_call, 
  10.                        LPVOID lpReserved
  11.                      )
  12. {
  13.     return TRUE;
  14. }
  15.  
  16. _declspec(dllexport) int filereader(LPCSTR fpath)
  17. {   int val=0,i=0;
  18.     fstream f;
  19.     string w;
  20.     f.open(fpath,ios::in);
  21.     if(f.is_open())
  22.     {
  23.        while(!f.eof())
  24.        {
  25.            getline(f,w);
  26.            i++;
  27.        }
  28.        val=i;
  29.        f.close();
  30.     }
  31.     else
  32.         val=-1;
  33.  
  34.     return val;
  35. }
  36.  
filedll.def
LIBRARY filedll
EXPORTS
filereader

BUT its not working..it just prints 1..even if the filename passed doesnot exist.
Jun 4 '07 #1
8 1617
Silent1Mezzo
208 New Member
So it looks like its getting into if(f.is_open()) whether the file is open or not. I don't know C++ but is it possible this is returning something other than 1?
Jun 4 '07 #2
happiness4all
52 New Member
no its not like dat...
its giving 1 in all da cases..if the file exists and there are many lines in it..
Jun 4 '07 #3
happiness4all
52 New Member
but the same code works fine if i run the function from simple program..instea d of calling the dll
Jun 4 '07 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Have you tried to follow the path of execution using your debugger??

Other questions:
1) have you loaded the dll??
2) have you used GetProcAddress? ?
Jun 4 '07 #5
happiness4all
52 New Member
yes i have done all that..
Jun 4 '07 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
yes i have done all that..
May I see what you have done?
Jun 4 '07 #7
weaknessforcats
9,208 Recognized Expert Moderator Expert
It just occurred to me:

You are aware that C++ mangles function names???

If you have .cpp file you will nedd to
a) use a DEF file to export the mangled name as a readable one
b) use extern "C" on your C++ function.

With a static lib, the mangled name is used throughout.

Or, you can forget all this and put your code in a .c file. Function names are not mangled in C and a DLL is an old C thingy.
Jun 4 '07 #8
happiness4all
52 New Member
I am confused about this mangled name..to be put in def file..

If the following dll works fine without mangled names and extern "C" ..why cant others..
Expand|Select|Wrap|Line Numbers
  1. deftry.cpp
  2. #include<iostream>
  3. #include<string>
  4. #include<windows.h>
  5. using namespace std;
  6.  
  7. _declspec(dllexport) int Add(int a,int b)
  8. {
  9.  
  10.     return (a+b);
  11. }
  12.  
deftry.def
LIBRARY deftry
EXPORTS
Add
Jun 5 '07 #9

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

Similar topics

2
13051
by: Count Dracula | last post by:
Is there a way to write a c++ program that will print out the last few lines of a file without reading the whole file? The implementations of 'tail' I have seen all appear to be system dependent. I am looking for a standard (portable) c++ solution that will do just a fraction of tail's functionality. To make a long story short, I am looking for suggestions that may help me improve the speed of the following implementation for long input...
18
4893
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
40
61233
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
5
3164
by: Martin Svensson | last post by:
Hello! I need some help/recommendations on how to do the following. I have a program that writes an IP address two control numbers and a date to file, on one line. It's a basic text file and it looks like this: ----- beginning of file ----- 192.168.0.1 0 0 2004-08-01 192.168.0.2 1 0 2004-08-21 192.168.0.4 0 1 2004-08-12
1
4002
by: Jose Reckoner | last post by:
I'm running python 2.3 on Windows XP. Anyone have a quick small script to convert .DT1 and .DEM data to ASCII or some other format? I don't need a viewer. Thanks!
9
5212
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still facing problems: Assume that FILE* filePointer; unsigned char lineBuffer;
4
2720
by: amatoo04 | last post by:
hi guys, i am trying to finish up a program i started this morning and basically i got the whole input and output down... i just need help with the function which will scan the file and return number of lines, amount of characters, and amount of alphabetical characters. I was wondering if i would need 3 different functions, and how would i go about setting those up. here is my code so far /*Write a program, which scans a file and counts...
5
2225
by: shermeenz | last post by:
the file which i have to read is: From sms@localhost.localdomain Wed May 16 10:46:03 2007 Return-Path: <sms@localhost.localdomain> Received: from localhost.localdomain (localhost.localdomain ) by localhost.localdomain (8.13.5/8.13.5) with ESMTP id l4GEk300002418 for <sms@localhost.localdomain>; Wed, 16 May 2007 10:46:03 -0400 Received: (from sms@localhost) by localhost.localdomain (8.13.5/8.13.5/Submit) id l4GEk3H3002417 for sms; Wed, 16...
9
7385
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying to read was maindata.xml . I cannot however seem to use the gzip module correctly. Have tried the program 2 ways for no success, any ideas would be appreciated. Attempt 1 #!/usr/bin/python
63
3267
by: Bill Cunningham | last post by:
I don't think I can do this without some help or hints. Here is the code I have. #include <stdio.h> #include <stdlib.h> double input(double input) { int count=0,div=0; double mean=0,linput=0; FILE *fpr, *fpw;
0
9628
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10292
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.