Click here to Skip to main content
15,898,371 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: SHChangeNotifyRegister notification Pin
David Crow6-Sep-05 2:52
David Crow6-Sep-05 2:52 
QuestionFile Search Pin
bugDanny2-Sep-05 4:14
bugDanny2-Sep-05 4:14 
AnswerRe: File Search Pin
Cedric Moonen2-Sep-05 4:24
Cedric Moonen2-Sep-05 4:24 
QuestionRe: File Search Pin
bugDanny2-Sep-05 5:06
bugDanny2-Sep-05 5:06 
AnswerRe: File Search Pin
David Crow2-Sep-05 8:54
David Crow2-Sep-05 8:54 
AnswerRe: File Search Pin
Gary R. Wheeler3-Sep-05 2:54
Gary R. Wheeler3-Sep-05 2:54 
QuestionContext Help whit several tabs fails Pin
Heyerdahl2-Sep-05 4:01
Heyerdahl2-Sep-05 4:01 
Questionsafearray access violation VBA to C++ Pin
Rimcon2-Sep-05 3:59
Rimcon2-Sep-05 3:59 
I'm writing a C++ DLL to speed up (run time over 1 hour) an excel macro. I read arrays in the macro, pass them to the DLL as SAFEARRAYs, identify the memory location, assign it to a new C++ array. I read some of the arrays and write to others. Then the excel macro reads the arrays and writes the results to a spreadsheet.

An early version of the program ran OK (50,000 loops through the arrays) -- after some early problems -- and the results were correct (I verified them manually in excel). The run time was reduced by a factor of over 10 !!!.

Then I expanded the program and now it freezes up -- never at the same place but always on the same type of command and always a memory access violation, either assigning the pointer to the C++ array or reading from/writing to the array.

The code looks like this:
In excel macro:


Code:
Option Explicit
Option Base 0

Public CF() As Double, IssuerCorrel() As Double, CRN() As Double, TransitionIndex() As Integer, TransCutoff(0 To 6, 0 To 7) As Double, IssuerEndRatingCode() As Integer

Declare Sub Cholesky Lib “C:\CreditRisk\CreditSim.dll” (IssuerCorrel() As Double, CF() As Double, ByVal IssuerCount As Integer)

Sub ScenarioGenerator()

Application.Calculation = xlCalculationManual: Application.ScreenUpdating = False: Application.EnableEvents = False

Dim IssuerCount As Integer,

Read in some data from spreadsheets

Dim IssuerCorrel(IssuerCount, IssuerCount) as Single; CF(IssuerCount, IssuerCount) as Single

Read more data from spreadsheets

Call Cholesky(IssuerCorrel(), CF(), ByVal IssuerCount)

Write some output data to spreadsheets

End Sub

In C++:


Code:
#include "stdafx.h"
#include <windows.h>
#include <oleauto.h>
#include "CreditSim.h"
#include "Oaidl.h"
#include <stdlib.h>
#include <math.h>
#include <time.h>

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

void __declspec (dllexport) __stdcall Cholesky(
SAFEARRAY **IssuerCorrel, SAFEARRAY **CF, short IssuerCount)
{
double L = 0.999999;
short n = IssuerCount;
long i = 0;long j = 0; long k = 0;

srand( (unsigned) time( NULL ) );

HRESULT SafeArrayLock( SAFEARRAY **IssuerCorrel );
HRESULT SafeArrayLock( SAFEARRAY **CF );

// Create new arrays that point to the Safearray data locations
double* CFc;
CFc = (double*)(*CF)->pvData;
CFc[0]= *CFc; Program fails here.

double* IssuerCorrelc;
IssuerCorrelc = (double*)(*IssuerCorrel)->pvData;
IssuerCorrelc [0] =*IssuerCorrelc; Program fails here.


CFc[n*(n-1)+n-1] = IssuerCorrelc[n*(n-1)+n-1];
for (j = n-2; j>=0; j--)
{
CFc[n*j + j] = IssuerCorrelc[n*j + j];
for (k = n-1; k>j; k--)
{
CFc[n*j + k] = IssuerCorrelc[n*j + k] * L;
for (i = k + 1; i
AnswerRe: safearray access violation VBA to C++ Pin
Branislav3-Sep-05 21:19
Branislav3-Sep-05 21:19 
QuestionEdit Box Style For 3D Look Pin
IndianOcean2-Sep-05 3:59
IndianOcean2-Sep-05 3:59 
AnswerRe: Edit Box Style For 3D Look Pin
PJ Arends2-Sep-05 8:42
professionalPJ Arends2-Sep-05 8:42 
GeneralRe: Edit Box Style For 3D Look Pin
IndianOcean4-Sep-05 21:45
IndianOcean4-Sep-05 21:45 
GeneralRe: Edit Box Style For 3D Look Pin
PJ Arends4-Sep-05 22:00
professionalPJ Arends4-Sep-05 22:00 
GeneralRe: Edit Box Style For 3D Look Pin
IndianOcean4-Sep-05 22:15
IndianOcean4-Sep-05 22:15 
GeneralRe: Edit Box Style For 3D Look Pin
PJ Arends4-Sep-05 22:25
professionalPJ Arends4-Sep-05 22:25 
Questionvc++ Pin
amitesh29112-Sep-05 3:59
sussamitesh29112-Sep-05 3:59 
AnswerRe: vc++ Pin
David Crow2-Sep-05 8:55
David Crow2-Sep-05 8:55 
Questionvc++ Pin
amitesh29112-Sep-05 3:58
sussamitesh29112-Sep-05 3:58 
QuestionMFC Application - Document handling Pin
KSMANN2-Sep-05 3:51
KSMANN2-Sep-05 3:51 
AnswerRe: MFC Application - Document handling Pin
Roger Allen2-Sep-05 6:44
Roger Allen2-Sep-05 6:44 
AnswerRe: MFC Application - Document handling Pin
ThatsAlok2-Sep-05 19:28
ThatsAlok2-Sep-05 19:28 
QuestionLoading Dll and calling class's methods Pin
Bernard382-Sep-05 3:38
Bernard382-Sep-05 3:38 
AnswerRe: Loading Dll and calling class's methods Pin
Cedric Moonen2-Sep-05 3:49
Cedric Moonen2-Sep-05 3:49 
GeneralRe: Loading Dll and calling class's methods Pin
Bernard382-Sep-05 4:36
Bernard382-Sep-05 4:36 
GeneralRe: Loading Dll and calling class's methods Pin
Cedric Moonen2-Sep-05 5:12
Cedric Moonen2-Sep-05 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.