Function Argument's value doesn't change

When I pass a string by reference and modify it, why doesn't it change in the calling procedure?

1
2
3
4
5
6
7
8
9
10
11
12
13
_declspec(dllexport) int ModStr(LPCTSTR str1, LPCTSTR str2, LPTSTR& str3)
{
	try
	{
		CString str3(str1);
		return 0;
	}
	catch (exception& x)
	{
		CString str3(str2);
		return 128;
	}
}


Declare the DLL Function in VBA and call it:

1
2
3
4
5
6
7
8
9
Public Declare Function ModStr Lib "Test123.dll" (ByVal str1 As String, _
ByVal str2 As String, ByRef str3 As String) As Long

Sub abc()
Dim myStr as String
myStr = String(16," ")
Debug.Print ModStr("Hello","W0rlD!", myStr) // Returns 0
Debug.Print myStr // Returns "                "
End Sub
You aren't modifying the parameter on line 5; you are creating a new local variable that hides the parameter.
Bah! I see.
I fixed it and it works fine...thanks!
Last edited on
Topic archived. No new replies allowed.