Changing data in the main program from a dll

I'm trying to write a dll that changes data in the main program.
I pass pointers to the data or pass pointers to functions in
the main program that change the data.  Everything works fine
in debug mode, but fails in the destructor in release mode.
Any ideas about why?
Thanks,
Ken


0
handsom (78)
11/12/2003 4:09:22 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
348 Views

Similar Articles

[PageSpeed] 40

Nothing obvious stands out. What type of dll is it, Regular or Extension? If its a regular
dll, are you playing with resources in your dll method that is calling the main program?

-- 
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"Ken->" <handsom@comcast.netspicedham> wrote in message
news:iq6dnR1EHsxpxy-iRVn-gQ@comcast.com...
| I'm trying to write a dll that changes data in the main program.
| I pass pointers to the data or pass pointers to functions in
| the main program that change the data.  Everything works fine
| in debug mode, but fails in the destructor in release mode.
| Any ideas about why?
| Thanks,
| Ken
|
|

0
ajaykalra (6842)
11/12/2003 8:36:13 PM
It is a regular dll and since I posted the original question, I have put in
some message boxes to check the values in the parameters I pass to the dll
and at least one of them gets messed up in the trip from the main program to
the dll.  I'm tryting to find out why that happens in release mode and not
in debug mode.
Ken

"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
news:uUIe7xVqDHA.2772@TK2MSFTNGP10.phx.gbl...
> Nothing obvious stands out. What type of dll is it, Regular or Extension?
If its a regular
> dll, are you playing with resources in your dll method that is calling the
main program?
>
> --
> Ajay Kalra [MVP - VC++]
> ajaykalra@yahoo.com
>
>
> "Ken->" <handsom@comcast.netspicedham> wrote in message
> news:iq6dnR1EHsxpxy-iRVn-gQ@comcast.com...
> | I'm trying to write a dll that changes data in the main program.
> | I pass pointers to the data or pass pointers to functions in
> | the main program that change the data.  Everything works fine
> | in debug mode, but fails in the destructor in release mode.
> | Any ideas about why?
> | Thanks,
> | Ken
> |
> |
>


0
handsom (78)
11/13/2003 5:02:00 PM
Ken-> wrote:

>I'm trying to write a dll that changes data in the main program.
>I pass pointers to the data or pass pointers to functions in
>the main program that change the data.  Everything works fine
>in debug mode, but fails in the destructor in release mode.
>Any ideas about why?

The destructor of what?

In general, if you expect the EXE and DLL to share the same heap, C-level
file descriptors, and other CRT state, such that you can free memory in
module X that you malloc'd in module Y, and so forth, they all must link to
the same CRT DLL. That is, they should all be compiled with /MD (release
build) or /MDd (debug build) compiler options.

You can also get into trouble due to the way VC destroys globals and other
static duration data in DLLs. Each module, EXE or DLL, has its own private
list of static data to destroy, and each set of objects is destroyed as a
unit. To make a long story short, you aren't guaranteed the "destruction in
reverse order of construction" order that you have in a statically linked
program, or within individual modules of a dynamically linked program. For
example, it's easy to concoct an example in which the following sequence of
events occurs:

EXE: constructs global X
DLL: constructs local static Y
EXE: destroys X
DLL: destroys Y

The order of destruction of X and Y is reversed from what it should be,
which can lead to problems if the destruction of Y uses X. This sort of
thing can happen fairly easily when using singleton classes.

Also, because construction of global DLL data and destruction of global and
other static duration DLL data occurs within DllMain, you can be subject to
all the DllMain restrictions in your classes' ctors and dtors, for those
classes used as globals or local statics. So even if you avoid the DllMain
restrictions by using a singleton that is constructed on first use, if the
singleton destroys the object it manages at program termination, and it's
owned by a DLL, you're still subject to the DllMain restrictions in that
class's dtor.

-- 
Doug Harrison
Microsoft MVP - Visual C++
0
dsh (2498)
11/13/2003 6:13:22 PM
"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:d5h7rvs4obve7a670a7pcf6msknr0t0mb2@4ax.com...
> Ken-> wrote:
>
> >I'm trying to write a dll that changes data in the main program.
> >I pass pointers to the data or pass pointers to functions in
> >the main program that change the data.  Everything works fine
> >in debug mode, but fails in the destructor in release mode.
> >Any ideas about why?
>
> The destructor of what?
>
> In general, if you expect the EXE and DLL to share the same heap, C-level
> file descriptors, and other CRT state, such that you can free memory in
> module X that you malloc'd in module Y, and so forth, they all must link
to
> the same CRT DLL. That is, they should all be compiled with /MD (release
> build) or /MDd (debug build) compiler options.
>
> You can also get into trouble due to the way VC destroys globals and other
> static duration data in DLLs. Each module, EXE or DLL, has its own private
> list of static data to destroy, and each set of objects is destroyed as a
> unit. To make a long story short, you aren't guaranteed the "destruction
in
> reverse order of construction" order that you have in a statically linked
> program, or within individual modules of a dynamically linked program. For
> example, it's easy to concoct an example in which the following sequence
of
> events occurs:
>
> EXE: constructs global X
> DLL: constructs local static Y
> EXE: destroys X
> DLL: destroys Y
>
> The order of destruction of X and Y is reversed from what it should be,
> which can lead to problems if the destruction of Y uses X. This sort of
> thing can happen fairly easily when using singleton classes.
>
> Also, because construction of global DLL data and destruction of global
and
> other static duration DLL data occurs within DllMain, you can be subject
to
> all the DllMain restrictions in your classes' ctors and dtors, for those
> classes used as globals or local statics. So even if you avoid the DllMain
> restrictions by using a singleton that is constructed on first use, if the
> singleton destroys the object it manages at program termination, and it's
> owned by a DLL, you're still subject to the DllMain restrictions in that
> class's dtor.
>
> --
> Doug Harrison
> Microsoft MVP - Visual C++


The destructor is of an object that was allocated in the EXE and modified by
the DLL.  The dtors seem to be called in the right order when I look at the
call stack.
BUT, I find I am having parameter passing troubles and hopefully
when I get that straightened out, the other problems will go away.
Ken


0
handsom (78)
11/13/2003 6:35:00 PM
Reply:

Similar Artilces:

Change the file name in Macro
I created Macro that open several workbooks (actually 17 of them) at the same time like this; Workbooks.Open Filename:= _ "H:\Month End Work\FY 2009\02-09 RUI SALES\01 - Feb09 CFW.xls" Workbooks.Open Filename:= _ "H:\Month End Work\FY 2009\02-09 RUI SALES\11 - Feb09 CFW.xls" Workbooks.Open Filename:= _ "H:\Month End Work\FY 2009\02-09 RUI SALES\21 - Feb09 CFW.xls" It works fine till I have to use it for the following month. I have to go back to my Macro and change manually the directory from 02-09 to 03-09 and file name from Feb09 to Mar0...

2007 excel autofilter change back to 2003 autofilter?
Is it possible to change the 2007 autofilter back to like the 2003 autofilter worked? I see you have a response to one of your other posts -- in a different forum. jonnybrovo815 wrote: > > Is it possible to change the 2007 autofilter back to like the 2003 autofilter > worked? -- Dave Peterson ...

Changing file in all upper case to upper and lower case
I have a file of names and addresses that were entered in all upper case. Is there a fast way to change this file into upper and lower case? Thanks for any help you can give me. -- S Jan http://www.mvps.org/dmcritchie/excel/proper.htm -- Regards, Peo Sjoblom (No private emails please) "Sagit" <Sagit@discussions.microsoft.com> wrote in message news:99B059C4-F5D8-4DD4-BABC-A16AFA3AA6D1@microsoft.com... >I have a file of names and addresses that were entered in all upper case. >Is > there a fast way to change this file into upper and lower case? Thanks &g...

Outlook 2007 ignoring "don't save changes" in calendar
HI, I have a strange problem with Outlook 2007 and am hoping someone can assist. It goes something like this: - I create a meeting request for 3pm today (the time doesn't matter) and send it to someone. - I then open up that appointment/meeting in my calendar and change the time to 5pm. - Before saving or sending the update I decide that I actually don't want to change the time of the meeting. - I press the X button to close the window and I'm asked whether I want to save the changes and send an update, or don't save changes. - I click don't save changes...

Change Business unit for Team
Is there a way to move a team from one Business unit to another? I can't find one. Ketil You can set the parent business unit of a team by using the SetParent method http://msdn.microsoft.com/library/en-us/crmsdk/htm/bizteamsetparentmethod.asp there are examples for C# too I hope this helps Andreas Donaubauer [MVP f�r CRM] MCP since 1999, MCSE, MCSA andreas[at]donaubauer.com http://www.crmfaq.de "Ketil Samuelsen" <ketilsam@frisurf.no> schrieb im Newsbeitrag news:5cdab81a.0501250110.3daad9fd@posting.google.com... > Is there a way to move a team from one Business...

Formula to sum in columns that change weekly
I enter a column of data weekly into a spread sheet and then total each row for the last 4,8& 12 weeks. As the column numbers to be added change weekly I have to change the formula weekly. Is there a way to do this automatically? Assuming no blanks, this will total the last 4, 8 and 12 weeks in row 2: =SUM(OFFSET($A$2,0,COUNTA($2:$2)-4,1,4) =SUM(OFFSET($A$2,0,COUNTA($2:$2)-8,1,8) =SUM(OFFSET($A$2,0,COUNTA($2:$2)-12,1,12) In article <lf%Lb.3326$Z%4.1704@newssvr24.news.prodigy.com>, "Robert L. Salisbury" <rlsalisbury@c-air-s.com> wrote: > I e...

DSUM not pulling the data
Using Excel XP. =============== I'm setting up a budget workbook, and one sheet (5 Year Strategic Plan) has a DSUM in it under a column labeled "2007": =DSUM(Capital,'Capital Projects'!$P$3,$E$39:$F$42)*12+DSUM(Capital,'Capital Projects'!$P$3,$V$17:$W$23) It shows "zero" as the value pulled, yet when I look at the sheet labeled "Capital Projects", I see 2 values that should have been pulled (just dummy data for now): $1500 on Jan 2007 and $2000 on June 2007. $E$39:$F$42 corresponds to: Capital Timing Land Monthly Buildings M...

summarizing selected data on a grid
I have a grid that I use to define attributes. I want to summarize only the selected "types" (i'm just using "x" to select on my grid). For example, by taking: A B C Type1 x Type2 x x Type3 x Type4 x x Type5 x x I want to output: A Type1 Type2 Type5 With similar output's for B & C. I could do it with if statements, but it's a pretty big grid, so I have a lot of blank rows. Is there a better way? Thanks. Hi! Have a look at your post: I suspect it has not reproduced as yo intended. The table of x's doesn't seem to match the scri...

Can't enter data in query datasheet
I have a query (involving multiple tables) that I want to execute and then use to enter/change data via the datasheet which results from the query. On most queries, I am able to do that. One this one, I can't. What is the criteria for determining what queries will allow data entry and which queries won't? What do I have to do to this query to allow data entry? SELECT [4GateMeetingTimes].Time, ActivityTbl.Activity_ActivityKey, ActivityTbl.Activity_Deployment, ActivityTbl.Activity_Name, ActivityTbl.Activity_Status, ActivityTbl.Activity_Type, ActivityTbl.Activity_Pl...

Why am I getting an error every time I close an Office program?
Whenever I exit Excel, Word or PowerPoint 2007 (not Outlook), I get the error message that Microsoft Office ***** needs to close. I've used the check online for a solution and haven't come up with anything. I've run office diagnositcs. I don't know what else to try. ...

Updating data in MS CRM from other places
Hi all We use relationships extensively but find that when using Advanced Find we can't define the joins necessary to create the set of Contacts required for a marketing list. (I think it would be good if I could save an Advanced Find, and then be able to use that within another Advanced Find - like a sub-query - but that's another matter). Anyway, as a quick solution, I have used queries in MS Access to identify the list of Contacts required. I have customised, adding a new field to the Contact table, and want to be able to set this field from in MS Access on those Contact ro...

how do i change the default directory in Outlook?
I do not use the My Documents Directory. The bulk of the files I save are kept on a server drive which is backed up daily. I wish Outlook to default to this server directory when I am saving. Outlook 2003. Jeff Bryenton <Jeff Bryenton@discussions.microsoft.com> wrote: > I do not use the My Documents Directory. The bulk of the files I save > are kept on a server drive which is backed up daily. I wish Outlook > to default to this server directory when I am saving. Outlook 2003. One way is to change the definition of "My Documents" so that it points to the server. A...

OWA2003 "Change Password" button problems?
The following link: http://support.microsoft.com/default.aspx?scid=kb;en-us;823175 describes how to change the urlscan.ini file to allow things to pass through unaffected. However now that I've got the "Change Password" button to appear, I get a "file not found" error when I click on it. I've used their ..ini file with a few modifications (to loosen it for my environment). I think I understand that because I run Exchange 2003 on Windows Server 2000, that I have to allow .htr files. I've done this but it still doesn't work. It says in one unqualified s...

How to ensure recipient can't change message
Is there a setting I can put on a message I send so that the recipient is prevented from changing any of the content, including attachments? Would this apply even when the recipient forwards the message? Use F1 help to read up on the topic of message sensitivity. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After furious head scratching, Hall asked: | Is there a setting I can put on a message I send so that the | reci...

can i change plot area colors for different date ranges
if i want to shade the plot area of a chart diferent colors, for example gray from Jan 1 through Fed 17, then white until March 10, is that possible? Will want to change the shadinging preiodically and fairly frequently. Thank you Hi, You should be able to use the technique explained on Jon's page http://peltiertech.com/Excel/Charts/ColoredVerticalBand.html Cheers Andy steve wrote: > if i want to shade the plot area of a chart diferent colors, for example gray > from Jan 1 through Fed 17, then white until March 10, is that possible? Will > want to change the shadinging pr...

UserForm Data to Spreadsheet
Is it possible when writing Userform data elements to a spreadsheet to specify exactly the cell you want the first piece of data to populate. I have tried a number of methods which allocate the data to the first available free cell or row but this is not exactly what I want to do here. For example, I would like to specify Cell "C4" to receive the first piece of data from the userform with subsequent pieces of data from that submission populating "D4,E4,F4" etc. The next time data is submitted from the Userform I would like it to start at "C5". Sorry for ...

Forumla to change values on situation
Hi all, I have a table of items with "value" "vat" and "total" Columns. I would like to write a formulae to say When value is less than 140.5 then change value to 85.5, vat to 14.96, total to 100.46 Else no change. so im guessings its something like: X=1 If AX<140.5 then AX=85.5, BX=14.96, CX=100.46 Else AX=AX,BX=BX,CX=CX Increment x Or i could just copy and paste the If Then statment down all the columns and forget the increment. Hopefully you will see what im trying to do. Thanks in advance, any help is much appretiated as always. Ernest Lai...

Customer Sales Data
Is there a way to merge duplicate names while at the same time adding the sales entry associated with the name entry. (Customer/Sales data was imported from Excel. If John Smith was a customer 4 times, there would be four "john smith" rows each with a different sales purchase amount in a separate column. I am trying to combine the 4 rows into a single john smith row but with the combined total sales amount of the 4 different purchases) Thanks! Sure. SELECT name, SUM(sale) FROM tableName GROUP BY name There is a rule for 'group by' or 'total' queries: ...

Excel Import goes thru without any data
Experts, I have been importing excel data to Project for years and never seen this problem. Today I was helping one of our users to import a list of assignments from Excel to a project schedule. We opened the excel file and went through the import wizard until we got to Finish. it went through but no data came in. I tried the same excel and same project files on my computer and everything worked fine. I did see that he did not have the "allow files with legacy format to open", but when I checked it didnt help either. what ami missing Hadi Hadi, What did you ...

Change Status by Worklfow not working!
I had a simple workflow to change account's status to active. The workflow is an "On demend" one. The workflow is running succeeded. The line in workflow isfor change record status is done. But the inactive account is not changed to active!!! No error found at all. The same workflow is working at another CRM installation(with rollupdate 2). The one has porblem is on rollupdate 4. Any help is great. Thanks -- MS CRM consultants at Melbourne Visit my CRM blog at http://melbournecrm.spaces.live.com/ ...

Forms - Call Data from Another Table
Hi I'm used to using lookups and forms etc but need to do something that I think links queries, VBA (completely new to) and forms: I have a form for creating new applicants I want to build a form that allows the user to search a contacts table on FirstName, MiddleName, Surname; receive a list of matches and then either 1. Select one of the matches which would then populate the applicants table or 2. Reject the matches and create a new record as normal Can you anyone point me in the right direction? Thanks James Sounds like you are asking how to do callbacks. Open a sub form ...

change build of myClassLib to Release instead of Debug?
I created a class library (dll) in "Active Debug" mode. After testing it out and seeing it works correctly I went to the Properties page of my Project to the Build section and changed the configuration to "Release" from "Active Debug". The Output Path says "bin\Release\" But when I click on Build myClassLib -- it is still building it in bin\Debug. How do I change this to bin\Release\? Thanks Rich *** Sent via Developersdex http://www.developersdex.com *** Rich P wrote: > I created a class library (dll) in "Active Debug"...

[MFC + DAO] Data selection
Hi, I've connection to database ( .mdb file) In one of tabels i've some fields: e.g like those: idTab - Autonumering idWho - Number idOK - Number idBad - Number And what i want to do is: const char pszIDTabFind[] = "idTab = %s "; CString strId - ID taken from another table CString str; str.Format( pszIDTabFind, strID ); RS.FindFirst ( str ); And what i get? An exception:/ !! Sth like : "Operation for this object is not supported" Why i can't find any data? What's more if i search for strings everything goes ok. Could You please tell me how should i...

Pivottable data field
I have noticed that when a field with no values is inserted in the layout as data, one of my pivottable shows this field as part of the pivottable, and on another it is excluded. Why the inconsistentcy? ...

Global wage data field for employee card
We are a new CAN GP Payroll user and find that having to change each pay code (REG, OT, etc) to their new wage without having it roll down from a master field very time consuming and poses potetial problems if a particular code is left out, calculated wrong, etc. Our previous payroll package was not as good as MGP overall but had a nice feature where changes to salary were made at the employee master card level and changes calculated and rolled down to each associated pay code type that was relevant for that empoyee. In MGP Payroll, if every employee in a company of 300 received a cha...