Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C++
CommandPtr pCmd = NULL;
_ParameterPtr Var1;
Var1 = pCmd->CreateParameter(_bstr_t("@T"), adInteger, adParamOutput, 0, codRet);


Why do I get Access violation writing... error in my dll on this string? How do I fix it?
Thx. I'm using VS 2015.

This is the full code:

C++
 CommandPtr pCmd = NULL;
_ConnectionPtr pConnection = NULL;
_bstr_t strMessage, strAuthorID;

::CoInitialize(NULL);

long codRet = -1;

try {

    _ParameterPtr Var1;


    TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
    hr = pConnection->Open("Driver={SQL Server};Server=conn_string", "", "", adConnectUnspecified);

    pConnection->CursorLocation = adUseClient;
    TESTHR(pCmd.CreateInstance(__uuidof(Command)));
    pCmd->CommandText = PrcName;
    pCmd->CommandType = adCmdStoredProc;

    Var1 = pCmd->CreateParameter(_bstr_t("@T"), adInteger, adParamOutput, 0, codRet);


What I have tried:

Trying to use my dll in 3d party application. DLL compiled successfully.
Posted
Updated 27-Jun-17 10:22am
v2
Comments
Richard Deeming 27-Jun-17 15:34pm    
Just because it compiles, that doesn't necessarily mean it's correct! :)
Member 13277231 27-Jun-17 15:40pm    
of course... So what might be a error?
Richard Deeming 27-Jun-17 15:45pm    
There are all sorts of possibilities. But without seeing the relevant parts of your code, there's very little chance that anyone will be able to tell you what the problem is.

Click the green "Improve question" link, and add the relevant parts of your DLL code to the question.

Then you'll just need to wait for someone who "does" C++ (I don't) to see if they can spot the problem.
Member 13277231 27-Jun-17 16:08pm    
I did. Thank you.

1 solution

CreateParameter(_bstr_t("@T"), adInteger, adParamOutput, 0, codRet);

The error seems to be was in 4th parameter which is size. I put 1 instead 0 and no error :)

CreateParameter Method (ADO) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900